From dbdf82da80cfc3a257ef54a555b72746bd2e1802 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Mon, 16 May 2022 16:30:55 -0400 Subject: [PATCH] UI: Fix memory leak with Manage Broadcast dialog When OBS has been connected to a YouTube account, the Manage Broadcast dialog becomes available. Opening and closing this dialog leaks about 2-3 MB of memory each time. This happens because the dialog is never deleted, and a new object is created every time the dialog opens. If we set Qt::WA_DeleteOnClose on the dialog, then the dialog->exec() call would call delete this. However, if the dialog->Valid() call returned false (this should currently be impossible), then exec is never called, so it would not clean up. To fix this, make the dialog stack-allocated instead of using new and delete. Detected by clang-analyzer. --- UI/window-basic-main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index dd85c1296..a26008c17 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -6668,12 +6668,10 @@ void OBSBasic::SetupBroadcast() #if YOUTUBE_ENABLED Auth *const auth = GetAuth(); if (IsYouTubeService(auth->service())) { - OBSYoutubeActions *dialog; - dialog = new OBSYoutubeActions(this, auth, broadcastReady); - connect(dialog, &OBSYoutubeActions::ok, this, + OBSYoutubeActions dialog(this, auth, broadcastReady); + connect(&dialog, &OBSYoutubeActions::ok, this, &OBSBasic::YouTubeActionDialogOk); - int result = dialog->Valid() ? dialog->exec() - : QDialog::Rejected; + int result = dialog.Valid() ? dialog.exec() : QDialog::Rejected; if (result != QDialog::Accepted) { if (!broadcastReady) ui->broadcastButton->setChecked(false);