Optimized against possible memory leaks
authorKurt Pattyn <pattyn.kurt@gmail.com>
Mon, 12 Aug 2013 19:09:05 +0000 (21:09 +0200)
committerKurt Pattyn <pattyn.kurt@gmail.com>
Mon, 12 Aug 2013 19:09:05 +0000 (21:09 +0200)
source/websocket.cpp
source/websocketserver.cpp
test/tst_compliance.cpp

index eb87ff3..99bbee3 100644 (file)
@@ -119,10 +119,11 @@ WebSocket::~WebSocket()
 {
        if (state() == QAbstractSocket::ConnectedState)
        {
-               //qDebug() << "GOING_AWAY, connection closed.";
                close(WebSocketProtocol::CC_GOING_AWAY, "Connection closed");
-               releaseConnections(m_pSocket);
        }
+       releaseConnections(m_pSocket);
+       m_pSocket->deleteLater();
+       m_pSocket = 0;
 }
 
 /*!
index 5892875..fa46e7a 100644 (file)
@@ -18,6 +18,12 @@ WebSocketServer::WebSocketServer(QObject *parent) :
 
 WebSocketServer::~WebSocketServer()
 {
+       while (!m_pendingConnections.isEmpty())
+       {
+               WebSocket *pWebSocket = m_pendingConnections.dequeue();
+               pWebSocket->close(WebSocketProtocol::CC_GOING_AWAY, "Server closed.");
+               pWebSocket->deleteLater();
+       }
        m_pTcpServer->deleteLater();
 }
 
index 6a8423a..7dc909d 100644 (file)
@@ -79,8 +79,9 @@ void ComplianceTest::runTestCase(int nbr, int total)
        url.setQuery(query);
        pWebSocket->open(url);
        spy.wait(60000);
-       //pWebSocket->close();
-       //delete pWebSocket;
+       pWebSocket->close();
+       delete pWebSocket;
+       pWebSocket = 0;
        runTestCase(nbr + 1, total);
 }
 
@@ -121,7 +122,8 @@ void ComplianceTest::autobahnTest()
        url.setQuery(query);
        pWebSocket->open(url);
        spy.wait(60000);
-       //delete pWebSocket;
+       delete pWebSocket;
+       pWebSocket = 0;
 }
 
 DECLARE_TEST(ComplianceTest)