From: Debian Qt/KDE Maintainers Date: Mon, 21 Feb 2022 21:00:28 +0000 (+0000) Subject: QNAM: work around QObject finicky orphan cleanup details X-Git-Tag: archive/raspbian/5.15.2+dfsg-15+rpi1^2~28 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d2b0462bfe6a4f5271e472f2d58b59e29bc3a7d8;p=qtbase-opensource-src.git QNAM: work around QObject finicky orphan cleanup details Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=0807f16eb407eaf8 Last-Update: 2021-01-26 Gbp-Pq: Name qnam_connect_memory_leak.diff --- diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 21916f53f..727c1a031 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -808,7 +808,17 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq // For the synchronous HTTP, this is the normal way the delegate gets deleted // For the asynchronous HTTP this is a safety measure, the delegate deletes itself when HTTP is finished - QObject::connect(thread, SIGNAL(finished()), delegate, SLOT(deleteLater())); + QMetaObject::Connection threadFinishedConnection = + QObject::connect(thread, SIGNAL(finished()), delegate, SLOT(deleteLater())); + + // QTBUG-88063: When 'delegate' is deleted the connection will be added to 'thread''s orphaned + // connections list. This orphaned list will be cleaned up next time 'thread' emits a signal, + // unfortunately that's the finished signal. It leads to a soft-leak so we do this to disconnect + // it on deletion so that it cleans up the orphan immediately. + QObject::connect(delegate, &QObject::destroyed, delegate, [threadFinishedConnection]() { + if (bool(threadFinishedConnection)) + QObject::disconnect(threadFinishedConnection); + }); // Set the properties it needs delegate->httpRequest = httpRequest;