Do not call deleteLater on a null QObject

We don't always have a pairing handler for a given device link

Also change the assert not to trigger a warning in ubsan

Reviewed by Albert Vaca
This commit is contained in:
Albert Astals Cid 2018-03-24 19:00:43 +01:00
parent 2008490ad9
commit 17b304c42a

View file

@ -404,12 +404,15 @@ void LanLinkProvider::deviceLinkDestroyed(QObject* destroyedDeviceLink)
{
const QString id = destroyedDeviceLink->property("deviceId").toString();
//qCDebug(KDECONNECT_CORE) << "deviceLinkDestroyed" << id;
Q_ASSERT(m_links.key(static_cast<LanDeviceLink*>(destroyedDeviceLink)) == id);
QMap< QString, LanDeviceLink* >::iterator linkIterator = m_links.find(id);
Q_ASSERT(linkIterator != m_links.end());
if (linkIterator != m_links.end()) {
Q_ASSERT(linkIterator.value() == destroyedDeviceLink);
m_links.erase(linkIterator);
m_pairingHandlers.take(id)->deleteLater();
auto pairingHandler = m_pairingHandlers.take(id);
if (pairingHandler) {
pairingHandler->deleteLater();
}
}
}