From 2fab1971fed22a9aa852e8df8155b6d5da83279d Mon Sep 17 00:00:00 2001 From: Robert Griebl Date: Wed, 18 Nov 2020 23:12:35 +0100 Subject: [PATCH] Fix memory corruption in QDBusInterface signal emissions If more than one signal parameter required conversions (e.g. 2 QVariantMaps), then the auxParameter list would be reallocated on the second append. This resulted in the reference to the first conversion (stored in params) to be broken. Found with valgrind after the QtApplicationManager started crashing weirdly when built against Qt 6. The same code is in Qt 5, but it just works fine there: I guess the reallocation strategy in QList is different there, so we never have to reallocate the list. Change-Id: I2e0c8906ebc9474c4ec9f53cafc1689003d5c4c5 Reviewed-by: Thiago Macieira --- src/dbus/qdbusintegrator.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 96f2244e0c..114931f3de 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -926,7 +926,9 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q QVarLengthArray params; params.reserve(metaTypes.count()); - QVariantList auxParameters; + QVarLengthArray auxParameters; // we cannot allow reallocation here, since we + auxParameters.reserve(metaTypes.count()); // keep references to the entries + // let's create the parameter list // first one is the return type -- add it below