Skip to content

Commit

Permalink
Fix segmentation fault during util_abort
Browse files Browse the repository at this point in the history
Fall back to printing things to stderr if `fopen` fails.
  • Loading branch information
pinkwah committed Nov 15, 2021
1 parent 2e7cb07 commit 1c0af7f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/util/util_abort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ 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")) {
abort_dump_path = make_dump_path();
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",
Expand Down

0 comments on commit 1c0af7f

Please sign in to comment.