From eca8bae6718d2cba788713bfb677f92f2fa3ca4e Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 15 Jan 2020 18:08:34 +0100 Subject: Fix T51054: NULL-dereferences in crash-handler callback --- source/creator/creator_signals.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source/creator') diff --git a/source/creator/creator_signals.c b/source/creator/creator_signals.c index e8c6e9251bc..446f8f51875 100644 --- a/source/creator/creator_signals.c +++ b/source/creator/creator_signals.c @@ -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 { -- cgit v1.2.3