diff --git a/src/file.js.c b/src/file.js.c index f2299ecd..a15fd72a 100644 --- a/src/file.js.c +++ b/src/file.js.c @@ -162,21 +162,20 @@ static void _file_write_write_callback(uv_fs_t* req) static void _file_write_open_callback(uv_fs_t* req) { + fs_req_t* fsreq = (fs_req_t*)req; uv_fs_req_cleanup(req); tf_task_t* task = req->loop->data; JSContext* context = tf_task_get_context(task); promiseid_t promise = (promiseid_t)(intptr_t)req->data; if (req->result >= 0) { - size_t size = 0; - memcpy(&size, req + 1, sizeof(size)); - uv_buf_t buf = { .base = (char*)(req + 1) + sizeof(size), .len = size }; - uv_file file = req->result; - int result = uv_fs_write(req->loop, req, file, &buf, 1, 0, _file_write_write_callback); + uv_buf_t buf = { .base = fsreq->buffer, .len = fsreq->size }; + fsreq->file = req->result; + int result = uv_fs_write(req->loop, req, fsreq->file, &buf, 1, 0, _file_write_write_callback); if (result < 0) { tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); - result = uv_fs_close(req->loop, req, file, _file_async_close_callback); + result = uv_fs_close(req->loop, req, fsreq->file, _file_async_close_callback); } } else diff --git a/src/socket.js.c b/src/socket.js.c index da471a7d..ad517882 100644 --- a/src/socket.js.c +++ b/src/socket.js.c @@ -592,11 +592,18 @@ void _socket_shutdownInternal(socket_t* socket, promiseid_t promise) void _socket_processTlsShutdown(socket_t* socket, promiseid_t promise) { - tf_tls_session_shutdown(socket->_tls); - if (!_socket_processSomeOutgoingTls(socket, promise, _socket_onTlsShutdown)) + if (!socket->_tls) { _socket_shutdownInternal(socket, promise); } + else + { + tf_tls_session_shutdown(socket->_tls); + if (!_socket_processSomeOutgoingTls(socket, promise, _socket_onTlsShutdown)) + { + _socket_shutdownInternal(socket, promise); + } + } } void _socket_onTlsShutdown(uv_write_t* request, int status) diff --git a/src/taskstub.js.c b/src/taskstub.js.c index 55a51d22..58c6cf6d 100644 --- a/src/taskstub.js.c +++ b/src/taskstub.js.c @@ -258,9 +258,22 @@ static void _taskstub_cleanup(tf_taskstub_t* stub) static void _taskstub_finalizer(JSRuntime* runtime, JSValue value) { tf_taskstub_t* stub = JS_GetOpaque(value, _classId); - stub->_on_exit = JS_UNDEFINED; - stub->_on_error = JS_UNDEFINED; - stub->_on_print = JS_UNDEFINED; + JSContext* context = tf_task_get_context(stub->_owner); + if (!JS_IsUndefined(stub->_on_exit)) + { + JS_FreeValue(context, stub->_on_exit); + stub->_on_exit = JS_UNDEFINED; + } + if (!JS_IsUndefined(stub->_on_error)) + { + JS_FreeValue(context, stub->_on_error); + stub->_on_error = JS_UNDEFINED; + } + if (!JS_IsUndefined(stub->_on_print)) + { + JS_FreeValue(context, stub->_on_print); + stub->_on_print = JS_UNDEFINED; + } tf_packetstream_destroy(stub->_stream); stub->_stream = NULL; stub->_finalized = true;