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 <hatem.elkharashy@qt.io> Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
This commit is contained in:
parent
257b3161c5
commit
bb8aada627
@ -15,6 +15,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
static bool s_initialized = false;
|
static bool s_initialized = false;
|
||||||
static bool s_triedLoading = false;
|
static bool s_triedLoading = false;
|
||||||
static bool s_prevent_recursion = false;
|
static bool s_prevent_recursion = false;
|
||||||
|
static bool s_shutdown = false;
|
||||||
static QCtfLib* s_plugin = nullptr;
|
static QCtfLib* s_plugin = nullptr;
|
||||||
|
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
@ -59,18 +60,13 @@ static bool loadPlugin(bool &retry)
|
|||||||
s_plugin = qobject_cast<QCtfLib *>(loader.instance());
|
s_plugin = qobject_cast<QCtfLib *>(loader.instance());
|
||||||
if (!s_plugin)
|
if (!s_plugin)
|
||||||
return false;
|
return false;
|
||||||
QObject *obj = loader.instance();
|
s_plugin->shutdown(&s_shutdown);
|
||||||
if (obj) {
|
|
||||||
QObject::connect(obj, &QObject::destroyed, []() {
|
|
||||||
s_plugin = nullptr;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool initialize()
|
static bool initialize()
|
||||||
{
|
{
|
||||||
if (s_prevent_recursion)
|
if (s_shutdown || s_prevent_recursion)
|
||||||
return false;
|
return false;
|
||||||
if (s_initialized || s_triedLoading)
|
if (s_initialized || s_triedLoading)
|
||||||
return s_initialized;
|
return s_initialized;
|
||||||
|
@ -232,6 +232,7 @@ public:
|
|||||||
virtual void doTracepoint(const QCtfTracePointEvent &point, const QByteArray &arr) = 0;
|
virtual void doTracepoint(const QCtfTracePointEvent &point, const QByteArray &arr) = 0;
|
||||||
virtual bool sessionEnabled() = 0;
|
virtual bool sessionEnabled() = 0;
|
||||||
virtual QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) = 0;
|
virtual QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) = 0;
|
||||||
|
virtual void shutdown(bool *shutdown) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -50,6 +50,7 @@ void QCtfLibImpl::cleanup()
|
|||||||
{
|
{
|
||||||
if (s_instance)
|
if (s_instance)
|
||||||
delete s_instance;
|
delete s_instance;
|
||||||
|
s_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCtfLibImpl::QCtfLibImpl()
|
QCtfLibImpl::QCtfLibImpl()
|
||||||
|
@ -78,6 +78,10 @@ public:
|
|||||||
QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) override;
|
QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) override;
|
||||||
void registerMetadata(const QCtfTraceMetadata &metadata);
|
void registerMetadata(const QCtfTraceMetadata &metadata);
|
||||||
int eventId();
|
int eventId();
|
||||||
|
void shutdown(bool *) override
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static QCtfLib *instance();
|
static QCtfLib *instance();
|
||||||
static void cleanup();
|
static void cleanup();
|
||||||
|
@ -22,9 +22,13 @@ public:
|
|||||||
~QCtfTracePlugin()
|
~QCtfTracePlugin()
|
||||||
{
|
{
|
||||||
m_cleanup = true;
|
m_cleanup = true;
|
||||||
|
*m_shutdown = true;
|
||||||
QCtfLibImpl::cleanup();
|
QCtfLibImpl::cleanup();
|
||||||
}
|
}
|
||||||
|
void shutdown(bool *shutdown) override
|
||||||
|
{
|
||||||
|
m_shutdown = shutdown;
|
||||||
|
}
|
||||||
bool tracepointEnabled(const QCtfTracePointEvent &point) override
|
bool tracepointEnabled(const QCtfTracePointEvent &point) override
|
||||||
{
|
{
|
||||||
if (m_cleanup)
|
if (m_cleanup)
|
||||||
@ -51,6 +55,7 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
bool m_cleanup = false;
|
bool m_cleanup = false;
|
||||||
|
bool *m_shutdown = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "qctfplugin.moc"
|
#include "qctfplugin.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user