From 4c1df115ecfb14c353c0ec46efdb1f9d2fc0ea95 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. Pick-to: 6.6 6.5 Change-Id: Ifee3f4e19835536f4a6cfa4f6866ab621581ad4f Reviewed-by: Thiago Macieira --- 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 543b185df9e..f1b586f58d7 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);