From 068e0cbb2f238486ed1b204a1ff4d7800a17c6f1 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 10 Jul 2023 13:52:49 +0200 Subject: [PATCH] QDbus: Avoid memory leak in registerComplexDBusType QMetaType does not own the interface from which it is constructed. Consequently, we end up with a memory leak. This is not a huge issue, given that the map of meta-types is static, and the application is about to be close when can discard it anyway, but it causes avoidable sanitizer warnings, which are annoying when debugging more severe memory leaks. Change-Id: Ifee3f4e19835536f4a6cfa4f6866ab621581ad4f Reviewed-by: Thiago Macieira (cherry picked from commit 4c1df115ecfb14c353c0ec46efdb1f9d2fc0ea95) Reviewed-by: Qt Cherry-pick Bot --- src/dbus/qdbusmetaobject.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp index 2e367e63acd..44437be33ad 100644 --- a/src/dbus/qdbusmetaobject.cpp +++ b/src/dbus/qdbusmetaobject.cpp @@ -116,8 +116,11 @@ static int registerComplexDBusType(const QByteArray &typeName) { ~Hash() { - for (QMetaType entry : *this) + for (QMetaType entry : std::as_const(*this)) { + auto iface = static_cast(entry.iface()); QMetaType::unregisterMetaType(std::move(entry)); + delete iface; + } } } hash; QMutexLocker lock(&mutex);