Fix a crash on shutdown in ~SocketApi #3057
authorJocelyn Turcotte <jturcotte@woboq.com>
Wed, 1 Apr 2015 12:40:34 +0000 (14:40 +0200)
committerJocelyn Turcotte <jturcotte@woboq.com>
Wed, 1 Apr 2015 13:03:42 +0000 (15:03 +0200)
Deleting the QLocalSocket while iterating the QList with qDeleteAll
would trigger onLostConnection, which would modify the list mid-air
and leave dangling pointers in it.

src/gui/socketapi.cpp

index 6bd86cc6291b074201d9a609e197cb3cbb1bcc75..9688c81b69e5aba3ce078dd8676f98a14b17d6d6 100644 (file)
@@ -136,7 +136,9 @@ SocketApi::~SocketApi()
 {
     DEBUG << "dtor";
     _localServer.close();
-    qDeleteAll(_listeners);
+    // All remaining sockets will be destroyed with _localServer, their parent
+    Q_ASSERT(_listeners.isEmpty() || _listeners.first()->parent() == &_localServer);
+    _listeners.clear();
     slotClearExcludesList();
 }