From 83bdbbb4dcb7121e609528428a8c6eb5d5528909 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 7 Jun 2022 02:41:44 +0000 Subject: [PATCH] Fixed some socket leaks. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3897 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/httpd.js | 2 +- src/socket.js.c | 9 +++------ src/util.js.c | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/httpd.js b/core/httpd.js index a104aa1e..0fd5a5d7 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -464,7 +464,7 @@ function handleConnection(client) { bodyToRead = parseInt(headers["content-length"]); lineByLine = false; if (bodyToRead > 16 * 1024 * 1024) { - badRequest(client, 'Reuqest too large: ' + bodyToRead + '.'); + badRequest(client, 'Request too large: ' + bodyToRead + '.'); return false; } body = new Uint8Array(bodyToRead); diff --git a/src/socket.js.c b/src/socket.js.c index bb04bccf..a89ad43e 100644 --- a/src/socket.js.c +++ b/src/socket.js.c @@ -237,11 +237,6 @@ void _socket_close_internal(socket_t* socket) void _socket_finalizer(JSRuntime *runtime, JSValue value) { socket_t* socket = JS_GetOpaque(value, _classId); - if (socket->_listening) - { - printf("FINALIZING A LISTENING SOCKET!\n"); - abort(); - } socket->_object = JS_UNDEFINED; _socket_close_internal(socket); } @@ -582,7 +577,9 @@ JSValue _socket_accept(JSContext* context, JSValueConst this_val, int argc, JSVa JSValue _socket_close(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { socket_t* socket = JS_GetOpaque(this_val, _classId); - if (socket->_closePromise == -1) + if (socket->_closePromise == -1 && + socket->_socket.data && + !uv_is_closing((uv_handle_t*)&socket->_socket)) { JSValue result = tf_task_allocate_promise(socket->_task, &socket->_closePromise); _socket_close_internal(socket); diff --git a/src/util.js.c b/src/util.js.c index 724c39d9..cac74c62 100644 --- a/src/util.js.c +++ b/src/util.js.c @@ -168,6 +168,7 @@ static void _util_timeoutCallback(uv_timer_t* handle) NULL); tf_util_report_error(context, result); JS_FreeValue(context, result); + JS_FreeValue(context, timeout->_callback); tf_trace_end(tf_task_get_trace(timeout->_task)); tf_free(timeout); uv_close((uv_handle_t*)handle, _handle_closed);