Patch from: https://gitlab.com/wireshark/wireshark/-/commit/b4d6d76c6eba2da7f8df55c328607fe651037c03 Removed hunk #2 which was for Stratoshark. From b4d6d76c6eba2da7f8df55c328607fe651037c03 Mon Sep 17 00:00:00 2001 From: John Thacker Date: Sat, 22 Feb 2025 10:19:36 -0500 Subject: [PATCH] Qt: Return from main instead of calling exit_application If the main event loop isn't running (and it can't be if we reach the clean_exit label in main()), then exit_application just calls stdlib exit. Returning from main does the same thing, execept the QApplication (function scoped) will be destroyed first. That's better for dealing with KDE Breeze mixing thread_local and QThreadStorage and having deleteLater. It ensures that objects get deleted before all the thread_local storage is destroyed. I can't replicate #14395 after this change, including by putting in the extra goto clean_exit mentioned in that issue's comments, on Qt 5.15, Qt 6, and different OSes. Fix #20370 --- ui/qt/main.cpp | 14 +++++++++++++- ui/stratoshark/stratoshark_main.cpp | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index e73496d4017..6d22ca43cc9 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -117,9 +117,21 @@ void main_window_update(void) } void exit_application(int status) { + // It's generally better to return from main. If the event loop is + // running (or has already stopped), wsApp->quit will cause the app + // to do so. (So we wouldn't need to call stdlib exit.) If it's not + // yet running, e.g., failure parsing options in ui/commandline.c, + // it's would be cleaner to return back to main and exit from there, + // especially if wsApp has been created. if (wsApp) { + // wsApp->quit() is a no-op if the event loop isn't running + // (That was not true in some earlier versions of Qt.) + // wsApp->exit(status) is not thread safe, though it may be possible to call + //QMetaObject::invokeMethod(wsApp, "exit", Qt::QueuedConnection, status); + // or similar, e.g. with a QTimer wsApp->quit(); } + // Calling stdlib exit here does not call the wsApp destructor. exit(status); } @@ -1128,5 +1140,5 @@ clean_exit: wtap_cleanup(); free_progdirs(); commandline_options_free(); - exit_application(ret_val); + return ret_val; }