diff options
author | Antti Määttä <[email protected]> | 2023-03-20 08:17:52 +0200 |
---|---|---|
committer | Janne Koskinen <[email protected]> | 2023-04-26 10:46:06 +0000 |
commit | bb8aada627e23a7f7e23dfdb97d443f1b847086a (patch) | |
tree | 24f21a652528e03e6bbc20a44bba5e3ba3c634e1 | |
parent | 257b3161c5c5e46cd040371da77cb6a06987cf50 (diff) |
Fix crash at exit when tracing
The crash is caused by the cleanup sending trace messages when the
plugin has already been destroyed. Add shutdown callback to the plugin
to indicate this has happened. We can't use signals since that also
generetes trace event.
Pick-to: 6.5
Change-Id: I2e490fc51c2aaa97c240c1496a528a6ff6077bd0
Reviewed-by: Hatem ElKharashy <[email protected]>
Reviewed-by: Janne Koskinen <[email protected]>
-rw-r--r-- | src/corelib/tracing/qctf.cpp | 10 | ||||
-rw-r--r-- | src/corelib/tracing/qctf_p.h | 1 | ||||
-rw-r--r-- | src/plugins/tracing/qctflib.cpp | 1 | ||||
-rw-r--r-- | src/plugins/tracing/qctflib_p.h | 4 | ||||
-rw-r--r-- | src/plugins/tracing/qctfplugin.cpp | 7 |
5 files changed, 15 insertions, 8 deletions
diff --git a/src/corelib/tracing/qctf.cpp b/src/corelib/tracing/qctf.cpp index 1dafa582d91..00a196c926f 100644 --- a/src/corelib/tracing/qctf.cpp +++ b/src/corelib/tracing/qctf.cpp @@ -15,6 +15,7 @@ QT_BEGIN_NAMESPACE static bool s_initialized = false; static bool s_triedLoading = false; static bool s_prevent_recursion = false; +static bool s_shutdown = false; static QCtfLib* s_plugin = nullptr; #if defined(Q_OS_ANDROID) @@ -59,18 +60,13 @@ static bool loadPlugin(bool &retry) s_plugin = qobject_cast<QCtfLib *>(loader.instance()); if (!s_plugin) return false; - QObject *obj = loader.instance(); - if (obj) { - QObject::connect(obj, &QObject::destroyed, []() { - s_plugin = nullptr; - }); - } + s_plugin->shutdown(&s_shutdown); return true; } static bool initialize() { - if (s_prevent_recursion) + if (s_shutdown || s_prevent_recursion) return false; if (s_initialized || s_triedLoading) return s_initialized; diff --git a/src/corelib/tracing/qctf_p.h b/src/corelib/tracing/qctf_p.h index 0e39b74e9e4..b8db869e09a 100644 --- a/src/corelib/tracing/qctf_p.h +++ b/src/corelib/tracing/qctf_p.h @@ -232,6 +232,7 @@ public: virtual void doTracepoint(const QCtfTracePointEvent &point, const QByteArray &arr) = 0; virtual bool sessionEnabled() = 0; virtual QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) = 0; + virtual void shutdown(bool *shutdown) = 0; }; QT_END_NAMESPACE diff --git a/src/plugins/tracing/qctflib.cpp b/src/plugins/tracing/qctflib.cpp index c3fdeed6607..bfbe6b2d877 100644 --- a/src/plugins/tracing/qctflib.cpp +++ b/src/plugins/tracing/qctflib.cpp @@ -50,6 +50,7 @@ void QCtfLibImpl::cleanup() { if (s_instance) delete s_instance; + s_instance = nullptr; } QCtfLibImpl::QCtfLibImpl() diff --git a/src/plugins/tracing/qctflib_p.h b/src/plugins/tracing/qctflib_p.h index 081dda1d044..d92730ec576 100644 --- a/src/plugins/tracing/qctflib_p.h +++ b/src/plugins/tracing/qctflib_p.h @@ -78,6 +78,10 @@ public: QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) override; void registerMetadata(const QCtfTraceMetadata &metadata); int eventId(); + void shutdown(bool *) override + { + + } static QCtfLib *instance(); static void cleanup(); diff --git a/src/plugins/tracing/qctfplugin.cpp b/src/plugins/tracing/qctfplugin.cpp index 8f2245bb286..daa2b3637e1 100644 --- a/src/plugins/tracing/qctfplugin.cpp +++ b/src/plugins/tracing/qctfplugin.cpp @@ -22,9 +22,13 @@ public: ~QCtfTracePlugin() { m_cleanup = true; + *m_shutdown = true; QCtfLibImpl::cleanup(); } - + void shutdown(bool *shutdown) override + { + m_shutdown = shutdown; + } bool tracepointEnabled(const QCtfTracePointEvent &point) override { if (m_cleanup) @@ -51,6 +55,7 @@ public: } private: bool m_cleanup = false; + bool *m_shutdown = nullptr; }; #include "qctfplugin.moc" |