Core: Replace a global std::unique_ptr

Amends 100e106e70.

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<Internal::MessageOutputWindow> 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
100e106e70. Note that there is also no leak when shutting down
"normally".

Change-Id: I8a1805f7710d70cbb5f5092842ab9b013bba2420
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-10-31 08:45:17 +01:00
parent 277f65e12d
commit 11d495a532

View File

@@ -9,8 +9,6 @@
#include <QFont> #include <QFont>
#include <memory>
/*! /*!
\namespace Core::MessageManager \namespace Core::MessageManager
\inheaderfile coreplugin/messagemanager.h \inheaderfile coreplugin/messagemanager.h
@@ -23,7 +21,7 @@
namespace Core::MessageManager { namespace Core::MessageManager {
static std::unique_ptr<Internal::MessageOutputWindow> s_messageOutputWindow; static Internal::MessageOutputWindow *s_messageOutputWindow = nullptr;
enum class Flag { Silent, Flash, Disrupt }; 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) static void writeImpl(const QString &text, Flag flags)
{ {
QTC_ASSERT(s_messageOutputWindow, return); 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() void init()
{ {
s_messageOutputWindow.reset(new Internal::MessageOutputWindow); s_messageOutputWindow = new Internal::MessageOutputWindow;
} }
/*! /*!
@@ -68,7 +66,8 @@ void init()
*/ */
void destroy() void destroy()
{ {
s_messageOutputWindow.reset(); delete s_messageOutputWindow;
s_messageOutputWindow = nullptr;
} }
/*! /*!