From 4c3a97d96e478dd54ee2a10205fc2520c33c6fda Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Thu, 24 May 2012 13:55:41 +0200 Subject: [PATCH] Fix bug #8170: Crash when client disconnects unexpectedly When the socket does not exist anymore, we should not try to access it. In trying to do so, std::map will create a new shared_ptr but this pointer doesn't point at anything. To prevent this, we explicitly check whether the socket is available. --- src/ServerSocket.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp index 7b9d6df5af..4c34212cb5 100644 --- a/src/ServerSocket.cpp +++ b/src/ServerSocket.cpp @@ -125,8 +125,10 @@ void ServerSocket::serverCallback() // if the connection has been closed void ServerSocket::dataCallback(int fd) { - shared_ptr client = clients[fd]; - + map >::const_iterator it = clients.find(fd); + if (it == clients.end()) + return; + shared_ptr client = it->second; string line; size_t pos; bool saidbye = false;