GUI: Delay deletion of child widgets when rebuilding launcher and options dialog

This is to avoid writing in deleted memory in the ButtonWidget::sendCommand
when the sent command results in the parent dialog being rebuilt.
This commit is contained in:
Thierry Crozat 2017-03-10 02:05:27 +00:00
parent cc75d17e9c
commit 1a874f9c07
2 changed files with 8 additions and 2 deletions

View file

@ -204,7 +204,10 @@ void LauncherDialog::clean() {
while (_firstWidget) { while (_firstWidget) {
Widget* w = _firstWidget; Widget* w = _firstWidget;
removeWidget(w); removeWidget(w);
delete w; // This is called from rebuild() which may result from handleCommand being called by
// a child widget sendCommand call. In such a case sendCommand is still being executed
// so we should not delete yet the child widget. Thus delay the deletion.
g_gui.addToTrash(w, this);
} }
delete _browser; delete _browser;
delete _loadDialog; delete _loadDialog;

View file

@ -423,7 +423,10 @@ void OptionsDialog::clean() {
while (_firstWidget) { while (_firstWidget) {
Widget* w = _firstWidget; Widget* w = _firstWidget;
removeWidget(w); removeWidget(w);
delete w; // This is called from rebuild() which may result from handleCommand being called by
// a child widget sendCommand call. In such a case sendCommand is still being executed
// so we should not delete yet the child widget. Thus delay the deletion.
g_gui.addToTrash(w, this);
} }
init(); init();
} }