From 11d495a532909d883e136141364d3340fb24aea2 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 31 Oct 2024 08:45:17 +0100 Subject: [PATCH] Core: Replace a global std::unique_ptr Amends 100e106e7023. When using FVWM's "Destroy" is used to end Qt Creator (which I do regularly) effectively only the X connection is cut. Consequently xcb_connection_has_error() returns true, triggering an immediate, unconditional exit(1) in QXcbConnection::processXcbEvents(). [This is arguably a bug or at least unfortunate behavior - the application should be given a chance to handle this gracefully] As a consequence, none of the application's own shutdown code is executed, but stdlib's exit handlers are run nevertheless. In case of the unique_ptr this will execute the MessageOutputWindow's dtor, triggering destruction of an Aggregate that apparently ends up in some half-destructed hash structure. Going back to plain pointer here replaces this behavior with the (less harmfull) leak that existed in that case before 100e106e7023. Note that there is also no leak when shutting down "normally". Change-Id: I8a1805f7710d70cbb5f5092842ab9b013bba2420 Reviewed-by: Jarek Kobus --- src/plugins/coreplugin/messagemanager.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/plugins/coreplugin/messagemanager.cpp b/src/plugins/coreplugin/messagemanager.cpp index d8e723ecf2c..730d4bfd710 100644 --- a/src/plugins/coreplugin/messagemanager.cpp +++ b/src/plugins/coreplugin/messagemanager.cpp @@ -9,8 +9,6 @@ #include -#include - /*! \namespace Core::MessageManager \inheaderfile coreplugin/messagemanager.h @@ -23,7 +21,7 @@ namespace Core::MessageManager { -static std::unique_ptr s_messageOutputWindow; +static Internal::MessageOutputWindow *s_messageOutputWindow = nullptr; enum class Flag { Silent, Flash, Disrupt }; @@ -52,7 +50,7 @@ static void doWrite(const QString &text, Flag flags) static void writeImpl(const QString &text, Flag flags) { QTC_ASSERT(s_messageOutputWindow, return); - QMetaObject::invokeMethod(s_messageOutputWindow.get(), [text, flags] { doWrite(text, flags); }); + QMetaObject::invokeMethod(s_messageOutputWindow, [text, flags] { doWrite(text, flags); }); } /*! @@ -60,7 +58,7 @@ static void writeImpl(const QString &text, Flag flags) */ void init() { - s_messageOutputWindow.reset(new Internal::MessageOutputWindow); + s_messageOutputWindow = new Internal::MessageOutputWindow; } /*! @@ -68,7 +66,8 @@ void init() */ void destroy() { - s_messageOutputWindow.reset(); + delete s_messageOutputWindow; + s_messageOutputWindow = nullptr; } /*!