From 03f0ceaf973fa5ead2aadf7ae68ee55aaae71216 Mon Sep 17 00:00:00 2001 From: Andrew Canaday Date: Fri, 7 Nov 2014 15:28:35 -0500 Subject: [PATCH] Be sure to invoke *lws_free_header_table*: * Just prior to freeing a session * When allocating a new header table This prevents some memory leaks we've found. --- lib/libwebsockets.c | 2 ++ lib/parsers.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 2844cc68..27201605 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -295,6 +295,8 @@ just_kill_connection: wsi->user_space && !wsi->user_space_externally_allocated) free(wsi->user_space); + /* As a precaution, free the header table in case it lingered: */ + lws_free_header_table(wsi); free(wsi); } diff --git a/lib/parsers.c b/lib/parsers.c index 7dd24fed..195325b1 100644 --- a/lib/parsers.c +++ b/lib/parsers.c @@ -61,6 +61,8 @@ int lextable_decode(int pos, char c) int lws_allocate_header_table(struct libwebsocket *wsi) { + /* Be sure to free any existing header data to avoid mem leak: */ + lws_free_header_table(wsi); wsi->u.hdr.ah = malloc(sizeof(*wsi->u.hdr.ah)); if (wsi->u.hdr.ah == NULL) { lwsl_err("Out of memory\n");