From a19d485b80d38296393577e699a8ce9ab235d388 Mon Sep 17 00:00:00 2001 From: Andrew Canaday Date: Fri, 7 Nov 2014 11:21:09 +0800 Subject: [PATCH] Don't free wsi->u.hdr.ah except through lws_free_header_table (exception: server.c frees 'ah' after copying the header pointer and transitioning the union state). --- lib/libwebsockets.c | 3 +-- lib/server-handshake.c | 5 +---- lib/server.c | 9 +++------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 5cf78eb..2844cc6 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -88,8 +88,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, context->protocols[0].callback(context, wsi, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, wsi->user_space, NULL, 0); - free(wsi->u.hdr.ah); - wsi->u.hdr.ah = NULL; + lws_free_header_table(wsi); goto just_kill_connection; } diff --git a/lib/server-handshake.c b/lib/server-handshake.c index 8a15054..ddfa275 100644 --- a/lib/server-handshake.c +++ b/lib/server-handshake.c @@ -268,10 +268,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi) bail: /* free up his parsing allocations */ - - if (wsi->u.hdr.ah) - free(wsi->u.hdr.ah); - + lws_free_header_table(wsi); return -1; } diff --git a/lib/server.c b/lib/server.c index 3e7e471..3d1d4c8 100644 --- a/lib/server.c +++ b/lib/server.c @@ -550,9 +550,7 @@ upgrade_ws: } /* drop the header info -- no bail_nuke_ah after this */ - - if (wsi->u.hdr.ah) - free(wsi->u.hdr.ah); + lws_free_header_table(wsi); wsi->mode = LWS_CONNMODE_WS_SERVING; @@ -589,8 +587,7 @@ upgrade_ws: bail_nuke_ah: /* drop the header info */ - if (wsi->u.hdr.ah) - free(wsi->u.hdr.ah); + lws_free_header_table(wsi); return 1; } @@ -713,7 +710,7 @@ int lws_server_socket_service(struct libwebsocket_context *context, lwsl_info("lws_server_skt_srv: read 0 len\n"); /* lwsl_info(" state=%d\n", wsi->state); */ if (!wsi->hdr_parsing_completed) - free(wsi->u.hdr.ah); + lws_free_header_table(wsi); /* fallthru */ case LWS_SSL_CAPABLE_ERROR: libwebsocket_close_and_free_session( -- 2.7.4