From 97850857b3d02d449b8c24bb1cd996ef1ea416d8 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 5 Jul 2014 10:31:12 +0800 Subject: [PATCH] dont free externally allocated user_space when closing connection Signed-off-by: Andy Green --- lib/client-handshake.c | 4 +++- lib/libwebsockets.c | 2 +- lib/private-libwebsockets.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) 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;