From 40f3da6a65d9c92c464168c9213df17b75ba3252 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 25 Feb 2024 19:38:00 -0500 Subject: [PATCH] Fix a leak in returning HTTP responses. --- src/httpd.js.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/httpd.js.c b/src/httpd.js.c index bd7ba33c..c11204d8 100644 --- a/src/httpd.js.c +++ b/src/httpd.js.c @@ -80,11 +80,13 @@ static JSValue _httpd_response_end(JSContext* context, JSValueConst this_val, in { tf_http_request_t* request = JS_GetOpaque(this_val, _httpd_request_class_id); size_t length = 0; + const char* cstring = NULL; const void* data = NULL; JSValue buffer = JS_UNDEFINED; if (JS_IsString(argv[0])) { - data = JS_ToCStringLen(context, &length, argv[0]); + cstring = JS_ToCStringLen(context, &length, argv[0]); + data = cstring; } else if ((data = tf_util_try_get_array_buffer(context, &length, argv[0])) != 0) { @@ -117,6 +119,10 @@ static JSValue _httpd_response_end(JSContext* context, JSValueConst this_val, in JS_FreeCString(context, headers[i]); } JS_FreeValue(context, buffer); + if (cstring) + { + JS_FreeCString(context, cstring); + } return JS_UNDEFINED; }