From 375cbc2cc4aa379727b7e0f02a257e1d8e35ce4f Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Fri, 7 Aug 2020 15:06:24 +0300 Subject: Node.js: correct port data memory release. According to libuv documentation, uv_poll_t memory should be released in a callback function passed to uv_close(). Otherwise, the Node.js application process may crash at exit. --- src/nodejs/unit-http/unit.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp index 975174d4..555b21fa 100644 --- a/src/nodejs/unit-http/unit.cpp +++ b/src/nodejs/unit-http/unit.cpp @@ -13,6 +13,8 @@ #include +static void delete_port_data(uv_handle_t* handle); + napi_ref Unit::constructor_; @@ -418,7 +420,8 @@ Unit::remove_port(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id) if (node_ctx->port_id == *port_id) { uv_poll_stop(&node_ctx->poll); - delete node_ctx; + node_ctx->poll.data = node_ctx; + uv_close((uv_handle_t *) &node_ctx->poll, delete_port_data); ctx->data = NULL; } @@ -428,6 +431,17 @@ Unit::remove_port(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id) } +static void +delete_port_data(uv_handle_t* handle) +{ + nxt_nodejs_ctx_t *node_ctx; + + node_ctx = (nxt_nodejs_ctx_t *) handle->data; + + delete node_ctx; +} + + void Unit::quit_cb(nxt_unit_ctx_t *ctx) { -- cgit