1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Guard Connection pointers with a QWeakPointer.

This commit is contained in:
Christian Muehlhaeuser
2011-09-06 03:06:46 +02:00
parent 700e53eb2c
commit 7a731c0fa5
2 changed files with 17 additions and 14 deletions

View File

@@ -443,7 +443,7 @@ Servent::socketConnected()
// qDebug() << "Servent::SocketConnected" << thread() << "socket:" << sock; // qDebug() << "Servent::SocketConnected" << thread() << "socket:" << sock;
Connection* conn = sock->_conn; Connection* conn = sock->_conn.data();
handoverSocket( conn, sock ); handoverSocket( conn, sock );
} }
@@ -472,28 +472,31 @@ void Servent::handoverSocket( Connection* conn, QTcpSocketExtra* sock )
void void
Servent::socketError( QAbstractSocket::SocketError e ) Servent::socketError( QAbstractSocket::SocketError e )
{ {
qDebug() << Q_FUNC_INFO;
QTcpSocketExtra* sock = (QTcpSocketExtra*)sender(); QTcpSocketExtra* sock = (QTcpSocketExtra*)sender();
if( !sock ) if ( !sock )
{ {
tLog() << "SocketError, sock is null"; tLog() << "SocketError, sock is null";
return; return;
} }
Connection* conn = sock->_conn; if ( !sock->_conn.isNull() )
if ( !conn ) {
Connection* conn = sock->_conn.data();
tLog() << "Servent::SocketError:" << e << conn->id() << conn->name();
if ( !sock->_disowned )
{
// connection will delete if we already transferred ownership, otherwise:
sock->deleteLater();
}
conn->markAsFailed(); // will emit failed, then finished
}
else
{ {
tLog() << "SocketError, connection is null"; tLog() << "SocketError, connection is null";
return;
}
tLog() << "Servent::SocketError:" << e << conn->id() << conn->name();
if( !sock->_disowned )
{
// connection will delete if we already transferred ownership, otherwise:
sock->deleteLater(); sock->deleteLater();
} }
conn->markAsFailed(); // will emit failed, then finished
} }

View File

@@ -63,7 +63,7 @@ public:
QTimer::singleShot( AUTH_TIMEOUT, this, SLOT( authTimeout() ) ) ; QTimer::singleShot( AUTH_TIMEOUT, this, SLOT( authTimeout() ) ) ;
} }
Connection* _conn; QWeakPointer<Connection> _conn;
bool _outbound; bool _outbound;
bool _disowned; bool _disowned;
msg_ptr _msg; msg_ptr _msg;