socket.io-poco icon indicating copy to clipboard operation
socket.io-poco copied to clipboard

Segfault when multiple SIOClients disconnect

Open 3dteemu opened this issue 10 years ago • 1 comments

SIOClient::connect(std::string uri) returns a pointer to a "global" client by calling SIOClientRegistry::instance()->getClient(fullpath). If a client to a specific URI already exists, SIOClient::connect returns a pointer to the existing client.

If the user "creates" multiple clients connecting the same server by calling SIOClient::connect, the user actually receives pointers to the same "global" client. The user does not know that without reading the source code. When the user disconnects the clients by calling client->disconnect(), they will all call code:

void SIOClient::disconnect() { _socket->disconnect(_endpoint); delete this; }

This results in a segfault, because all the client pointers become invalid when the first client calls disconnect.

Possible solution: Use reference counting and delete the actual client only when the last reference calls SIOClient::disconnect().

3dteemu avatar Apr 15 '14 12:04 3dteemu

On my fork i'm moving code to safer memory tools (C++11) https://github.com/gelldur/socket.io-poco/tree/cpp11

gelldur avatar Dec 27 '16 16:12 gelldur