diff options
author | Kimmo Karvinen <kkarvinen@broadsoft.com> | 2015-03-31 17:14:33 +0300 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-04-08 06:54:53 +0000 |
commit | 5b469aa3c4d6b9c68feb9cf92d03614077518894 (patch) | |
tree | 8d0889cd7eb6a389052e6a02978805a2f8092725 /src | |
parent | 8a370cead2f493ee961c814af96192a8db3e18e3 (diff) | |
download | qtwebsockets-5b469aa3c4d6b9c68feb9cf92d03614077518894.tar.gz |
Lifetime of incoming QTcpSocket/QSslSocket are managed by the
QTcpServer/QSslServer and thus the QWebSocketPrivate should clear the
pointer to the socket when the socket is destroyed.
Added auto test for the crash.
Task-number: QTBUG-45331
Change-Id: I6e30e7cdcca22aa810ccc1a1d4d7d77c7cb2c349
Reviewed-by: Steven Ceuppens <steven.ceuppens@icloud.com>
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/websockets/qwebsocket_p.cpp | 11 | ||||
-rw-r--r-- | src/websockets/qwebsocket_p.h | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index ced197e..76a5882 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -542,6 +542,10 @@ void QWebSocketPrivate::makeConnections(const QTcpSocket *pTcpSocket) QObject::connect(pTcpSocket, &QAbstractSocket::aboutToClose, q, &QWebSocket::aboutToClose); QObject::connect(pTcpSocket, &QAbstractSocket::bytesWritten, q, &QWebSocket::bytesWritten); + + QObjectPrivate::connect(pTcpSocket, &QObject::destroyed, + this, &QWebSocketPrivate::socketDestroyed); + //catch signals QObjectPrivate::connect(pTcpSocket, &QAbstractSocket::stateChanged, this, &QWebSocketPrivate::processStateChanged); @@ -1048,6 +1052,13 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS } } +void QWebSocketPrivate::socketDestroyed(QObject *socket) +{ + Q_ASSERT(m_pSocket); + if (m_pSocket.data() == socket) + m_pSocket.take(); +} + /*! \internal */ diff --git a/src/websockets/qwebsocket_p.h b/src/websockets/qwebsocket_p.h index f13e08d..85d3f49 100644 --- a/src/websockets/qwebsocket_p.h +++ b/src/websockets/qwebsocket_p.h @@ -162,6 +162,8 @@ private: void setSocketState(QAbstractSocket::SocketState state); void setErrorString(const QString &errorString); + void socketDestroyed(QObject *socket); + void processData(); void processPing(const QByteArray &data); void processPong(const QByteArray &data); |