Fix memory leaks with QDBusServer
Two serious mistakes: - we need to call dbus_server_free_data_slot as many times as we call dbus_server_allocate_data_slot - we need to delete the d pointer... The changes to the unit tests are simply to cause the used peer connections to be removed so they don't show up in valgrind. Change-Id: I9fd1ada5503db9ba481806c09116874ee81f450d Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>bb10
parent
a90bb5b89a
commit
fb16664893
|
|
@ -323,6 +323,8 @@ DEFINEFUNC(void , dbus_pending_call_unref, (DBusPendingCall
|
|||
/* dbus-server.h */
|
||||
DEFINEFUNC(dbus_bool_t , dbus_server_allocate_data_slot, (dbus_int32_t *slot_p),
|
||||
(slot_p), return)
|
||||
DEFINEFUNC(void , dbus_server_free_data_slot, (dbus_int32_t *slot_p),
|
||||
(slot_p), return)
|
||||
DEFINEFUNC(void , dbus_server_disconnect, (DBusServer *server),
|
||||
(server), )
|
||||
DEFINEFUNC(char* , dbus_server_get_address, (DBusServer *server),
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// used with dbus_server_allocate_data_slot
|
||||
static dbus_int32_t server_slot = -1;
|
||||
|
||||
static QBasicAtomicInt isDebugging = Q_BASIC_ATOMIC_INITIALIZER(-1);
|
||||
#define qDBusDebug if (::isDebugging == 0); else qDebug
|
||||
|
||||
|
|
@ -1084,8 +1087,10 @@ void QDBusConnectionPrivate::closeConnection()
|
|||
mode = InvalidMode; // prevent reentrancy
|
||||
baseService.clear();
|
||||
|
||||
if (server)
|
||||
if (server) {
|
||||
q_dbus_server_disconnect(server);
|
||||
q_dbus_server_free_data_slot(&server_slot);
|
||||
}
|
||||
|
||||
if (oldMode == ClientMode || oldMode == PeerMode) {
|
||||
if (connection) {
|
||||
|
|
@ -1651,8 +1656,6 @@ void QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg)
|
|||
handleSignal(key, msg); // third try
|
||||
}
|
||||
|
||||
static dbus_int32_t server_slot = -1;
|
||||
|
||||
void QDBusConnectionPrivate::setServer(DBusServer *s, const QDBusErrorInternal &error)
|
||||
{
|
||||
mode = ServerMode;
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ QDBusServer::~QDBusServer()
|
|||
}
|
||||
d->serverConnectionNames.clear();
|
||||
}
|
||||
d->deleteLater();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -294,6 +294,7 @@ void tst_QDBusConnection::connectToPeer()
|
|||
"", "newconn");
|
||||
QVERIFY(!con.isConnected());
|
||||
QVERIFY(con.lastError().isValid());
|
||||
QDBusConnection::disconnectFromPeer("newconn");
|
||||
}
|
||||
|
||||
QDBusServer server;
|
||||
|
|
@ -303,6 +304,7 @@ void tst_QDBusConnection::connectToPeer()
|
|||
"unix:abstract=/tmp/dbus-XXXXXXXXXX,guid=00000000000000000000000000000000", "newconn2");
|
||||
QVERIFY(!con.isConnected());
|
||||
QVERIFY(con.lastError().isValid());
|
||||
QDBusConnection::disconnectFromPeer("newconn2");
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue