From b5224b5de3bba2c976a201073b39af84865c7b98 Mon Sep 17 00:00:00 2001 From: borgmanJeremy <46930769+borgmanJeremy@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:42:20 -0600 Subject: [PATCH 1/2] When in CLI mode qApp needs to be deleted before exiting or Qt's destructor complains (because of the memory leak that would occur) (#4546) --- src/main.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 953c69ee2d..3c8b01838f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -529,7 +529,9 @@ int main(int argc, char* argv[]) req.addSaveTask(); } } - return requestCaptureAndWait(req); + int guiExitCode = requestCaptureAndWait(req); + delete qApp; + return guiExitCode; } else if (parser.isSet(fullArgument)) { // FULL reinitializeAsQApplication(argc, argv, translator, qtTranslator); @@ -564,7 +566,11 @@ int main(int argc, char* argv[]) if (!clipboard && path.isEmpty() && !raw && !upload) { req.addSaveTask(); } - return requestCaptureAndWait(req); + { + int fullExitCode = requestCaptureAndWait(req); + delete qApp; + return fullExitCode; + } } else if (parser.isSet(screenArgument)) { // SCREEN reinitializeAsQApplication(argc, argv, translator, qtTranslator); @@ -614,7 +620,11 @@ int main(int argc, char* argv[]) req.addSaveTask(); } - return requestCaptureAndWait(req); + { + int screenExitCode = requestCaptureAndWait(req); + delete qApp; + return screenExitCode; + } } else if (parser.isSet(configArgument)) { // CONFIG bool autostart = parser.isSet(autostartOption); bool notification = parser.isSet(notificationOption); @@ -680,6 +690,6 @@ int main(int argc, char* argv[]) } } finish: - + delete qApp; return 0; } From 4a32a7e86a15a67456d628e79d77d86cb7db2e7e Mon Sep 17 00:00:00 2001 From: borgmanJeremy <46930769+borgmanJeremy@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:42:25 -0600 Subject: [PATCH 2/2] Fix race condition caused by improper dbus hack (#4547) --- src/utils/valuehandler.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/valuehandler.cpp b/src/utils/valuehandler.cpp index 99c2bbe1da..fbd4bb502b 100644 --- a/src/utils/valuehandler.cpp +++ b/src/utils/valuehandler.cpp @@ -530,11 +530,15 @@ bool Region::check(const QVariant& val) QVariant Region::process(const QVariant& val) { - // FIXME: This is temporary, just before D-Bus is removed + // Create a temporary QApplication if there is no global Qt application + // instance at all. Creating one while a QCoreApplication already exists + // is forbidden by Qt: the second constructor aborts early, but its + // destructor still runs and corrupts global state (e.g. Wayland + // connections), causing subsequent portal calls to hang. auto argv = std::make_unique(1); auto argc = std::make_unique(0); std::unique_ptr tempApp; - if (QGuiApplication::screens().empty()) { + if (!QCoreApplication::instance()) { tempApp = std::make_unique(*argc, argv.get()); }