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

Proposed solution to "double free or corruption (out)" #12

Open
chil-dk opened this issue Sep 10, 2018 · 0 comments
Open

Proposed solution to "double free or corruption (out)" #12

chil-dk opened this issue Sep 10, 2018 · 0 comments

Comments

@chil-dk
Copy link

chil-dk commented Sep 10, 2018

I downloaded the code, and the examples didn't work.
I located what I think is an error in the buffer management.
The data type for the data waiting to be sent shouldn't be const char *, but strings.

struct Connection
{
    list<string>       buffer;     // <-- string and not const char*
    map<string,string> keyValueMap;
    time_t             createTime;
};

`
A copy of the incoming data should be made when pushing to the buffer:

A const char is just a pointer. If a pointer is pushed onto the buffer, and the pointer is for some reason no longer valid, then the buffer contains ... invalid data.
That's what I found when I put some debug statements into the code.
Here is what the echo server told me:

[cppWebSockets] Callback Receive
[cppWebSockets] Received: hjghjk
[cppWebSockets] send, socketID = 8 data = 'hjghjk'
[cppWebSockets] Callback Server Writeable, fd = 8
[cppWebSockets] == Elements in buffer: 1
[cppWebSockets] == Element : ���� [cppWebSockets] Sending '����'

The buffer elements was first pushed to the buffer in the WebSocketServer::send, and when the callback receive function asked for them, they were no longer valid.

Changing the datatype to string as shown solved the problem.

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

1 participant