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 <thiago.macieira@intel.com>
(cherry picked from commit 4c1df115ecfb14c353c0ec46efdb1f9d2fc0ea95)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Fabian Kosmale 2023-07-10 13:52:49 +02:00 committed by Qt Cherry-pick Bot
parent eb21238015
commit 068e0cbb2f

View File

@ -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<const QDBusRawTypeHandler *>(entry.iface());
QMetaType::unregisterMetaType(std::move(entry));
delete iface;
}
}
} hash;
QMutexLocker lock(&mutex);