From 1c0af7f321e36291948c82c1fa48654aaf21288c Mon Sep 17 00:00:00 2001 From: Zohar Malamant Date: Mon, 15 Nov 2021 10:19:00 +0100 Subject: [PATCH] Fix segmentation fault during util_abort Fall back to printing things to stderr if `fopen` fails. --- lib/util/util_abort.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/util/util_abort.cpp b/lib/util/util_abort.cpp index 44b8c9429..164896a41 100644 --- a/lib/util/util_abort.cpp +++ b/lib/util/util_abort.cpp @@ -90,7 +90,7 @@ extern "C" void util_abort__(const char *file, const char *function, int line, longjmp(test_jmp_buf, 0); } - FILE *abort_dump = stderr; + FILE *abort_dump = nullptr; #ifndef WIN32 std::string abort_dump_path; if (!getenv("ERT_SHOW_BACKTRACE")) { @@ -98,6 +98,8 @@ extern "C" void util_abort__(const char *file, const char *function, int line, abort_dump = fopen(abort_dump_path.c_str(), "w"); } #endif + if (abort_dump == nullptr) + abort_dump = stderr; print(abort_dump, "\n\nAbort called from: {} ({}:{})\n\nError message: {}\n\n",