payden / libwsclient

WebSocket client library for C
GNU General Public License v3.0
133 stars 73 forks source link

Possible data race during handshake #20

Open savethebeesandseeds opened 2 years ago

savethebeesandseeds commented 2 years ago

A possible data raise might mean some mutex lock is missing. on running Valgrind Helgrind, output shows:

==62338== Possible data race during write of size 1 at 0x1FC8CB94 by thread #2 ==62338== Locks held: 1, at address 0x1FC8CB38 ==62338== at 0x4B129E5: libwsclient_handshake_thread (wsclient.c:792) ==62338== by 0x484F30D: mythread_wrapper (hg_intercepts.c:406) ==62338== by 0x1C467B19: start_thread (pthread_create.c:443) ==62338== by 0x1C4EB8F3: clone (clone.S:100) ==62338== ==62338== This conflicts with a previous read of size 1 by thread #1 ==62338== Locks held: none ==62338== at 0x4B1157A: libwsclient_run (wsclient.c:50)

Fairly simple to resolve:

change: if(pthread_create(&client->handshake_thread, NULL, libwsclient_handshake_thread, (void *)client)) {

by: ibwsclient_handshake_thread((void *)client);

omitting the threading for the handshake solves it.