Branch: master

4cdf1eaf 2014-08-28 17:56:48 Timothy Pearson
Fix memory leak on calling TQT_DBusConnection::sendWithReply
Notably tdepowersave no longer leaks memory after this patch
M tqdbusconnection.cpp
diff --git a/tqdbusconnection.cpp b/tqdbusconnection.cpp
index a62735e..0360456 100644
--- a/tqdbusconnection.cpp
+++ b/tqdbusconnection.cpp
@@ -280,8 +280,8 @@
     DBusMessage *msg = message.toDBusMessage();
     if (!msg)
         return TQT_DBusMessage::fromDBusMessage(0);
-    DBusMessage *reply = dbus_connection_send_with_reply_and_block(d->connection, msg,
-                                                -1, &d->error);
+
+    DBusMessage *reply = dbus_connection_send_with_reply_and_block(d->connection, msg, -1, &d->error);
 
     if (d->handleError() && error)
         *error = d->lastError;
@@ -289,6 +289,9 @@
     dbus_message_unref(msg);
 
     TQT_DBusMessage ret = TQT_DBusMessage::fromDBusMessage(reply);
+    if (reply) {
+        dbus_message_unref(reply);
+    }
 
     bool dbus_error_set = dbus_error_is_set(&d->error);
     ret.d->error.setDBUSError(dbus_error_set);