From b73ff52fe684ad6c9216bf4934d7f8e9459ab7d3 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 10 Sep 2015 04:01:20 -0700 Subject: [PATCH] bindings: close after reading module struct Do not let the module struct to be deallocated by `uv_dlclose` before reading data from it. PR-URL: https://github.com/nodejs/node/pull/2792 Reviewed-By: Ben Noordhuis Reviewed-By: Brian White Reviewed-By: Yosuke Furukawa --- src/node.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 7075d28f68a24c..ba5643eaf50de1 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2120,12 +2120,15 @@ void DLOpen(const FunctionCallbackInfo& args) { return; } if (mp->nm_version != NODE_MODULE_VERSION) { - uv_dlclose(&lib); char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "Module version mismatch. Expected %d, got %d.", NODE_MODULE_VERSION, mp->nm_version); + + // NOTE: `mp` is allocated inside of the shared library's memory, calling + // `uv_dlclose` will deallocate it + uv_dlclose(&lib); env->ThrowError(errmsg); return; }