diff --git a/lib/client-handshake.c b/lib/client-handshake.c index 2e51bb4d..e25c368c 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -434,8 +434,10 @@ libwebsocket_client_connect_extended(struct libwebsocket_context *context, ssl_connection, path, host, origin, protocol, ietf_version_or_minus_one); - if (ws && !ws->user_space && userdata) + if (ws && !ws->user_space && userdata) { + ws->user_space_externally_allocated = 1; ws->user_space = userdata ; + } return ws ; } diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 2975f38e..e0525a54 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -279,7 +279,7 @@ just_kill_connection: LWS_CALLBACK_WSI_DESTROY, wsi->user_space, NULL, 0); if (wsi->protocol && wsi->protocol->per_session_data_size && - wsi->user_space) /* user code may own */ + wsi->user_space && !wsi->user_space_externally_allocated) free(wsi->user_space); free(wsi); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index cd2f1200..6fae8898 100755 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -581,6 +581,7 @@ struct libwebsocket { char rx_frame_type; /* enum libwebsocket_write_protocol */ unsigned int hdr_parsing_completed:1; + unsigned int user_space_externally_allocated:1; char pending_timeout; /* enum pending_timeout */ time_t pending_timeout_limit;