Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when multiple SIOClients disconnect #16

Open
3dteemu opened this issue Apr 15, 2014 · 1 comment
Open

Segfault when multiple SIOClients disconnect #16

3dteemu opened this issue Apr 15, 2014 · 1 comment

Comments

@3dteemu
Copy link

3dteemu commented Apr 15, 2014

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
Copy link

gelldur commented Dec 27, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants