SVN commit 1087546 by dfaure: And now the real fix for the dbus connection leak problem :/
Next step: doing the same (but not the same) in kdelibs/nepomuk. But at least the akonadiserver leak (triggered by kmail) is fixed by this. CCMAIL: [email protected] M +23 -10 queryserviceclient.cpp --- trunk/kdesupport/akonadi/server/src/search/queryserviceclient.cpp #1087545:1087546 @@ -40,21 +40,34 @@ { public: QDBusConnectionPerThreadHelper() - : m_counter( 0 ) { + : m_connection( QDBusConnection::connectToBus( + QDBusConnection::SessionBus, + QString::fromLatin1("NepomukQueryServiceConnection%1").arg(newNumber()) ) ) + { } - - QDBusConnection newConnection() { - QMutexLocker lock( &m_mutex ); - return QDBusConnection::connectToBus( QDBusConnection::SessionBus, - QString::fromLatin1("NepomukQueryServiceConnection%1").arg(++m_counter) ); + ~QDBusConnectionPerThreadHelper() { + QDBusConnection::disconnectFromBus( m_connection.name() ); } + static QDBusConnection threadConnection(); + private: - int m_counter; - QMutex m_mutex; + int newNumber() { + return m_counter.fetchAndAddAcquire(1); + } + QAtomicInt m_counter; + QDBusConnection m_connection; }; - Q_GLOBAL_STATIC(QDBusConnectionPerThreadHelper, s_globalDBusConnectionPerThreadHelper) + QThreadStorage<QDBusConnectionPerThreadHelper *> s_perThreadConnection; + + QDBusConnection QDBusConnectionPerThreadHelper::threadConnection() + { + if (!s_perThreadConnection.hasLocalData()) { + s_perThreadConnection.setLocalData(new QDBusConnectionPerThreadHelper); + } + return s_perThreadConnection.localData()->m_connection; + } } @@ -64,7 +77,7 @@ Private() : queryServiceInterface( 0 ), queryInterface( 0 ), - dbusConnection( s_globalDBusConnectionPerThreadHelper()->newConnection() ), + dbusConnection( QDBusConnectionPerThreadHelper::threadConnection() ), loop( 0 ) { } _______________________________________________ release-team mailing list [email protected] https://mail.kde.org/mailman/listinfo/release-team
