Skip to content

Commit

Permalink
bindings: close after reading module struct
Browse files Browse the repository at this point in the history
Do not let the module struct to be deallocated by `uv_dlclose`
before reading data from it.

PR-URL: #2792
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Yosuke Furukawa <[email protected]>
  • Loading branch information
indutny authored and rvagg committed Sep 11, 2015
1 parent 82ba183 commit 9683e5d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2087,12 +2087,15 @@ void DLOpen(const FunctionCallbackInfo<Value>& 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;
}
Expand Down

0 comments on commit 9683e5d

Please sign in to comment.