1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00

Use new function lws_free_header_table instead of free.

Prevents a couple of memory issues I've run into (double-free, free memory not malloc'ed, etc) caused by wsi->u.hdr.ah not being set to NULL after free.

Merge branch 'feature/hdr_free' into hdr_table_free

Conflicts:
	lib/libwebsockets.c
This commit is contained in:
Andrew Canaday 2014-11-06 21:04:48 -05:00
commit 7b09d023f7
5 changed files with 17 additions and 12 deletions

View file

@ -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;
}

View file

@ -73,6 +73,15 @@ int lws_allocate_header_table(struct libwebsocket *wsi)
return 0;
}
int lws_free_header_table(struct libwebsocket *wsi)
{
if( wsi->u.hdr.ah ) {
free( wsi->u.hdr.ah );
wsi->u.hdr.ah = NULL;
};
return 0;
};
LWS_VISIBLE int lws_hdr_total_length(struct libwebsocket *wsi, enum lws_token_indexes h)
{
int n;

View file

@ -1013,6 +1013,9 @@ lws_plat_set_socket_options(struct libwebsocket_context *context, int fd);
LWS_EXTERN int
lws_allocate_header_table(struct libwebsocket *wsi);
LWS_EXTERN int
lws_free_header_table(struct libwebsocket *wsi);
LWS_EXTERN char *
lws_hdr_simple_ptr(struct libwebsocket *wsi, enum lws_token_indexes h);

View file

@ -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;
}

View file

@ -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(