CTF: Remove channel from channel list when it is destroyed

Prevents using the channel after it was destroyed.

Change-Id: I5d65fcde0d451dd8ce2c56f403e0bd1f41510382
Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
This commit is contained in:
Antti Määttä 2023-05-24 15:20:49 +03:00
parent 62312e6674
commit 7f5d2262c1
2 changed files with 8 additions and 0 deletions

View File

@ -257,6 +257,7 @@ void QCtfLibImpl::writeCtfPacket(QCtfLibImpl::Channel &ch)
QCtfLibImpl::Channel::~Channel() QCtfLibImpl::Channel::~Channel()
{ {
impl->writeCtfPacket(*this); impl->writeCtfPacket(*this);
impl->removeChannel(this);
} }
QCtfLibImpl::~QCtfLibImpl() QCtfLibImpl::~QCtfLibImpl()
@ -266,6 +267,12 @@ QCtfLibImpl::~QCtfLibImpl()
qDeleteAll(m_eventPrivs); qDeleteAll(m_eventPrivs);
} }
void QCtfLibImpl::removeChannel(Channel *ch)
{
const QMutexLocker lock(&m_mutex);
m_channels.removeOne(ch);
}
bool QCtfLibImpl::tracepointEnabled(const QCtfTracePointEvent &point) bool QCtfLibImpl::tracepointEnabled(const QCtfTracePointEvent &point)
{ {
if (m_sessionChanged) { if (m_sessionChanged) {

View File

@ -89,6 +89,7 @@ public:
private: private:
static QCtfLibImpl *s_instance; static QCtfLibImpl *s_instance;
QHash<QString, QCtfTracePointPrivate *> m_eventPrivs; QHash<QString, QCtfTracePointPrivate *> m_eventPrivs;
void removeChannel(Channel *ch);
void updateMetadata(const QCtfTracePointEvent &point); void updateMetadata(const QCtfTracePointEvent &point);
void writeMetadata(const QString &metadata, bool overwrite = false); void writeMetadata(const QString &metadata, bool overwrite = false);
void clearLocation(); void clearLocation();