From 8f8ae06b515c0fe479ba8b3cfb27c354c031e483 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 9 Sep 2022 22:38:55 +1000 Subject: Fix use-after-free error when exiting on WIN32 The logging API was freed before calling wm_autosave_delete that called BKE_appdir_folder_id_create to get the auto-save location (when the temporary directory wasn't found). Detecting BLENDER_USER_AUTOSAVE would log details about the path, which would read data freed by CLG_exit. Resolve by calling CLG_exit last. --- source/blender/windowmanager/intern/wm_init_exit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 8163b39b3dd..283b87f1a2f 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -634,13 +634,15 @@ void WM_exit_ex(bContext *C, const bool do_python) BKE_sound_exit(); BKE_appdir_exit(); - CLG_exit(); BKE_blender_atexit(); wm_autosave_delete(); BKE_tempdir_session_purge(); + + /* Keep last (or near last) so logging can be used right up until everything is shut-down. */ + CLG_exit(); } void WM_exit(bContext *C) -- cgit v1.2.3