Fix T51054: NULL-dereferences in crash-handler callback

This commit is contained in:
Julian Eisel 2020-01-15 18:08:34 +01:00
parent ca49643f3c
commit eca8bae671
Notes: blender-bot 2023-02-14 07:07:14 +01:00
Referenced by issue #51054, Crash-handler crashes.
1 changed files with 7 additions and 4 deletions

View File

@ -102,15 +102,18 @@ static void sig_handle_crash_backtrace(FILE *fp)
static void sig_handle_crash(int signum)
{
wmWindowManager *wm = G_MAIN->wm.first;
/* Might be called after WM/Main exit, so needs to be careful about NULL-checking before
* dereferencing. */
wmWindowManager *wm = G_MAIN ? G_MAIN->wm.first : NULL;
# ifdef USE_WRITE_CRASH_BLEND
if (wm->undo_stack) {
if (wm && wm->undo_stack) {
struct MemFile *memfile = BKE_undosys_stack_memfile_get_active(wm->undo_stack);
if (memfile) {
char fname[FILE_MAX];
if (!G_MAIN->name[0]) {
if (!(G_MAIN && G_MAIN->name[0])) {
BLI_make_file_string("/", fname, BKE_tempdir_base(), "crash.blend");
}
else {
@ -131,7 +134,7 @@ static void sig_handle_crash(int signum)
char fname[FILE_MAX];
if (!G_MAIN->name[0]) {
if (!(G_MAIN && G_MAIN->name[0])) {
BLI_join_dirfile(fname, sizeof(fname), BKE_tempdir_base(), "blender.crash.txt");
}
else {