Fix for crash opening the file selector multiple times

This is part of a fix for T88570, where the file selector would crash
when activated multiple times.

Calling save multiple times would free the operator, leaving a dangling
pointer which was used when panels were visible that accessed the
"active_operator".

Reviewed By: Severin

Ref D14905
This commit is contained in:
Campbell Barton 2022-05-10 22:56:22 +10:00
parent 502c3d6c21
commit 9173dd24ad
Notes: blender-bot 2023-04-19 22:54:54 +02:00
Referenced by issue #95366, Crash when closing render window in "Save as".
1 changed files with 26 additions and 4 deletions

View File

@ -101,6 +101,7 @@ static int wm_operator_call_internal(bContext *C,
static bool wm_operator_check_locked_interface(bContext *C, wmOperatorType *ot);
static wmEvent *wm_event_add_mousemove_to_head(wmWindow *win);
static void wm_operator_free_for_fileselect(wmOperator *file_operator);
/* -------------------------------------------------------------------- */
/** \name Event Management
@ -2036,7 +2037,13 @@ void WM_event_remove_handlers(bContext *C, ListBase *handlers)
}
WM_cursor_grab_disable(win, NULL);
WM_operator_free(handler->op);
if (handler->is_fileselect) {
wm_operator_free_for_fileselect(handler->op);
}
else {
WM_operator_free(handler->op);
}
}
}
else if (handler_base->type == WM_HANDLER_TYPE_UI) {
@ -2473,6 +2480,22 @@ static int wm_handler_operator_call(bContext *C,
return WM_HANDLER_BREAK;
}
static void wm_operator_free_for_fileselect(wmOperator *file_operator)
{
LISTBASE_FOREACH (bScreen *, screen, &G_MAIN->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
if (area->spacetype == SPACE_FILE) {
SpaceFile *sfile = area->spacedata.first;
if (sfile->op == file_operator) {
sfile->op = NULL;
}
}
}
}
WM_operator_free(file_operator);
}
/**
* File-select handlers are only in the window queue,
* so it's safe to switch screens or area types.
@ -2668,7 +2691,7 @@ static int wm_handler_fileselect_do(bContext *C,
}
if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) {
WM_operator_free(handler->op);
wm_operator_free_for_fileselect(handler->op);
}
}
else {
@ -2683,8 +2706,7 @@ static int wm_handler_fileselect_do(bContext *C,
wm->op_undo_depth--;
}
}
WM_operator_free(handler->op);
wm_operator_free_for_fileselect(handler->op);
}
CTX_wm_area_set(C, NULL);