From f09f5ccd9b769252b08e62a538adaa31edf6b9b4 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 15 Sep 2022 09:36:13 +0200 Subject: QQmlDataBlob: Use RefPointer when interacting with QQmlTypeLoader QQmlTypeloader and QQmlTypeLoaderThread so far used to manually call ref and deref on QQmlDataBlob pointers. Changing the refcount was necessary, as the blobs were stored in various data structures which should keep the blobs alive; namely the Message struct subclasses use in QQmlThread and the NetworkReplies hash-map. However, the whole setup was rather brittle; especially when it comes to QQmlThread, where methods adding Message structs would increment the refcount, and the actual callback stored in the Message would decrement it. This would obviously cause leaks if the Message::call would not be invoked (e.g. due to the QQmlThread shutting down). By replacing the raw pointers with QQmlDataBlob::Ptr (which is a new typedef for QQmlRefPointer), we can avoid the whole issue[1], and also simplify the code. Note that Message stores a QQmlDataBlob::Ptr by virtue of inferring the type from its stored method. [1]: At least in theory; QQmlThread does not clean up its message list on shut-down so far. Change-Id: I6aaf5a9dcddfd38795059518ca2d3650072bcda3 Reviewed-by: Ulf Hermann Reviewed-by: Qt CI Bot --- src/qml/qml/qqmldatablob_p.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/qml/qml/qqmldatablob_p.h') diff --git a/src/qml/qml/qqmldatablob_p.h b/src/qml/qml/qqmldatablob_p.h index e975043871..522d02e97a 100644 --- a/src/qml/qml/qqmldatablob_p.h +++ b/src/qml/qml/qqmldatablob_p.h @@ -38,6 +38,8 @@ class QQmlTypeLoader; class Q_QML_PRIVATE_EXPORT QQmlDataBlob : public QQmlRefCount { public: + using Ptr = QQmlRefPointer; + enum Status { Null, // Prior to QQmlTypeLoader::load() Loading, // Prior to data being received and dataReceived() being called -- cgit v1.2.3