From d5d8496cd285cf988884e99d29d76367cfcd742f Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Tue, 13 Aug 2019 13:58:26 +0300 Subject: [PATCH] Use RAII to manage QApplication memory Signed-off-by: Konstantin Kharlamov --- src/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f27cc215..22a0ce8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // KDE #include @@ -103,7 +104,8 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char *argv[]) qputenv("QT_NO_GLIB", "1"); #endif - auto app = new QApplication(argc, argv); + // Allocate QApplication on the heap for the KDBusService workaround + auto app = std::unique_ptr(new QApplication(argc, argv)); app->setStyle(new MenuStyle()); #if defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(5, 11, 2)) @@ -219,15 +221,11 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char *argv[]) // 2. An invalid situation occurred const bool continueStarting = (konsoleApp.newInstance() != 0); if (!continueStarting) { - delete app; return 0; } } - // Since we've allocated the QApplication on the heap for the KDBusService workaround, - // we need to delete it manually before returning from main(). int ret = app->exec(); - delete app; return ret; }