himynameschris / socket.io-poco

cross platform c++ socket.io client written using poco libraries
116 stars 39 forks source link

Segfault when multiple SIOClients disconnect #16

Open 3dteemu opened 10 years ago

3dteemu commented 10 years ago

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().

gelldur commented 7 years ago

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