From 3667e556dbde5f1138783c31f2c499c8d8dd85ec Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Mon, 24 Feb 2020 15:29:12 -0800 Subject: [PATCH] UI: Use deleteLater() rather than explicit delete When an audio source is removed, it signals its "destroy" callbacks. One of the callbacks is OBSSourceLabel::SourceDestroyed. When its Qt destroy signal is fired, it causes a call to LoadAudioSources to refresh the source list. LoadAudioSources deletes the old layout, and so the QWidget that the OBSSource is based on is freed while it's still in the middle of running the signal callback, resulting in access to freed memory. --- UI/window-basic-settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index e742a9223..75bf5e082 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -2142,7 +2142,7 @@ void OBSBasicSettings::LoadAudioSources() { if (ui->audioSourceLayout->rowCount() > 0) { QLayoutItem *forDeletion = ui->audioSourceLayout->takeAt(0); - delete forDeletion->widget(); + forDeletion->widget()->deleteLater(); delete forDeletion; } auto layout = new QFormLayout();