Fixed some socket leaks.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3897 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-06-07 02:41:44 +00:00
parent 1dc6084d2d
commit 83bdbbb4dc
3 changed files with 5 additions and 7 deletions

View File

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

View File

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

View File

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