Skip to content

Commit

Permalink
GTK: fix a crash when clicking Cancel on Change Settings.
Browse files Browse the repository at this point in the history
I only observed this in the GTK1 build, but I don't know for sure it
can't happen in other situations, so there's no reason not to be
careful.

What seems to happen is that when the user clicks Cancel on the Change
Settings dialog box, we call gtk_widget_destroy on the window, which
emits the "destroy" signal on the window, our handler for which frees
the whole dlgparam. But _then_ GTK goes through and cleans up all the
sub-widgets of the dialog box, and some of those generate extra
events. In particular, destroying a list box is done by first deleting
all the list entries - and if one of those is selected, the list box's
selection changes, triggering an event which calls our callback that
tries to look up the control in the dlgparam we just freed.

My simple workaround is to defer actually freeing the dlgparam, via a
toplevel callback. Then it's still lying around empty while all those
random events are firing.
  • Loading branch information
sgtatham committed Dec 7, 2024
1 parent 6a88b29 commit 296b629
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion unix/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -3345,9 +3345,18 @@ static void dlgparam_destroy(GtkWidget *widget, gpointer data)
sfree(dp->selparams[i]);
}
sfree(dp->selparams);
dp->selparams = NULL;
}
#endif
sfree(dp);
/*
* Instead of freeing dp right now, defer it until we return to
* the GTK main loop. Then if any other last-minute GTK events
* happen while the rest of the widgets are being cleaned up, our
* handlers will still be able to try to look things up in dp.
* (They won't find anything - we've just emptied it - but at
* least they won't crash while trying.)
*/
queue_toplevel_callback(sfree, dp);
}

static void messagebox_handler(dlgcontrol *ctrl, dlgparam *dp,
Expand Down

0 comments on commit 296b629

Please sign in to comment.