From 45b57b715f1f0d99a274ec0ad1a1cc3f6798bbf3 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 13 Sep 2011 10:47:10 +0200 Subject: [PATCH] * Use a QWeakPointer to guard Connection pointers. --- src/libtomahawk/network/servent.cpp | 10 +++++----- src/libtomahawk/network/servent.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libtomahawk/network/servent.cpp b/src/libtomahawk/network/servent.cpp index d4bd8de5b..3d26e6b04 100644 --- a/src/libtomahawk/network/servent.cpp +++ b/src/libtomahawk/network/servent.cpp @@ -241,7 +241,7 @@ Servent::setExternalAddress( QHostAddress ha, unsigned int port ) void Servent::registerOffer( const QString& key, Connection* conn ) { - m_offers[key] = QPointer(conn); + m_offers[key] = QWeakPointer(conn); } @@ -629,7 +629,7 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString if( m_offers.contains( key ) ) { - QPointer conn = m_offers.value( key ); + QWeakPointer conn = m_offers.value( key ); if( conn.isNull() ) { // This can happen if it's a streamconnection, but the audioengine has @@ -642,21 +642,21 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString if( !nodeid.isEmpty() ) { // If there isn't a nodeid it's not the first connection and will already have been stopped - if( !checkACL( conn, nodeid, true ) ) + if( !checkACL( conn.data(), nodeid, true ) ) { tLog() << "Connection not allowed due to ACL"; return NULL; } } - if( conn->onceOnly() ) + if( conn.data()->onceOnly() ) { m_offers.remove( key ); return conn.data(); } else { - return conn->clone(); + return conn.data()->clone(); } } else if ( noauth ) diff --git a/src/libtomahawk/network/servent.h b/src/libtomahawk/network/servent.h index 8ead47b3b..273004376 100644 --- a/src/libtomahawk/network/servent.h +++ b/src/libtomahawk/network/servent.h @@ -158,7 +158,7 @@ private: QJson::Parser parser; QList< ControlConnection* > m_controlconnections; // canonical list of authed peers - QMap< QString, QPointer > m_offers; + QMap< QString, QWeakPointer > m_offers; int m_port, m_externalPort; QHostAddress m_externalAddress; QString m_externalHostname;