summaryrefslogtreecommitdiffhomepage
path: root/src/nodejs/unit-http
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-08-07 15:06:24 +0300
committerMax Romanov <max.romanov@nginx.com>2020-08-07 15:06:24 +0300
commit375cbc2cc4aa379727b7e0f02a257e1d8e35ce4f (patch)
treebc39fe6d922a1b8a27762f6514dd79dd13b4e498 /src/nodejs/unit-http
parent78fd04adcf398a00549c4912f68eff77c94ab6c0 (diff)
downloadunit-375cbc2cc4aa379727b7e0f02a257e1d8e35ce4f.tar.gz
unit-375cbc2cc4aa379727b7e0f02a257e1d8e35ce4f.tar.bz2
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.
Diffstat (limited to '')
-rw-r--r--src/nodejs/unit-http/unit.cpp16
1 files changed, 15 insertions, 1 deletions
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 <nxt_unit_websocket.h>
+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)
{