From 63a73a4a55e9433760e21102bf15d088cf7af0db Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Tue, 29 Dec 2020 01:05:10 -0800 Subject: [PATCH] Fix debug console instance leak Each time the debug console is launched, a new instance is created, but never deleted. To fix, create one instance, if the option is enabled, and show that one each time the menu option is selected. --- src/ui/mainwindow.cpp | 8 ++++---- src/ui/mainwindow.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 91c5942a6..c5db3fb4e 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -172,6 +172,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, edit_tag_dialog_(std::bind(&MainWindow::CreateEditTagDialog, this)), love_dialog_(std::bind(&MainWindow::CreateLoveDialog, this)), stream_discoverer_(std::bind(&MainWindow::CreateStreamDiscoverer, this)), + debug_console_(std::bind(&MainWindow::CreateDebugConsole, this)), global_shortcuts_(new GlobalShortcuts(this)), global_search_view_(new GlobalSearchView(app_, this)), library_view_(new LibraryViewContainer(this)), @@ -2740,6 +2741,8 @@ StreamDiscoverer* MainWindow::CreateStreamDiscoverer() { return discoverer; } +Console* MainWindow::CreateDebugConsole() { return new Console(app_, this); } + void MainWindow::ShowAboutDialog() { about_dialog_->show(); } void MainWindow::ShowTranscodeDialog() { transcode_dialog_->show(); } @@ -3075,10 +3078,7 @@ void MainWindow::DoGlobalSearch(const QString& query) { global_search_view_->StartSearch(query); } -void MainWindow::ShowConsole() { - Console* console = new Console(app_, this); - console->show(); -} +void MainWindow::ShowConsole() { debug_console_->show(); } void MainWindow::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Space) { diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 4a4a74adb..1f032b938 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -43,6 +43,7 @@ class Application; class ArtistInfoView; class BackgroundStreams; class CommandlineOptions; +class Console; class CoverProviders; class Database; class DeviceManager; @@ -268,6 +269,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { EditTagDialog* CreateEditTagDialog(); LoveDialog* CreateLoveDialog(); StreamDiscoverer* CreateStreamDiscoverer(); + Console* CreateDebugConsole(); void OpenSettingsDialog(); void OpenSettingsDialogAtPage(SettingsDialog::Page page); void ShowSongInfoConfig(); @@ -318,6 +320,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { Lazy love_dialog_; Lazy about_dialog_; Lazy stream_discoverer_; + Lazy debug_console_; GlobalShortcuts* global_shortcuts_;