Skip to content

Commit

Permalink
src: fix memory leak in DLOpen
Browse files Browse the repository at this point in the history
PR-URL: #2375
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
skomski authored and Fishrock123 committed Aug 19, 2015
1 parent a3160c0 commit b196c1d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {

if (is_dlopen_error) {
Local<String> errmsg = OneByteString(env->isolate(), uv_dlerror(&lib));
uv_dlclose(&lib);
#ifdef _WIN32
// Windows needs to add the filename into the error message
errmsg = String::Concat(errmsg, args[1]->ToString(env->isolate()));
Expand All @@ -2133,10 +2134,12 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
}

if (mp == nullptr) {
uv_dlclose(&lib);
env->ThrowError("Module did not self-register.");
return;
}
if (mp->nm_version != NODE_MODULE_VERSION) {
uv_dlclose(&lib);
char errmsg[1024];
snprintf(errmsg,
sizeof(errmsg),
Expand All @@ -2146,6 +2149,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
return;
}
if (mp->nm_flags & NM_F_BUILTIN) {
uv_dlclose(&lib);
env->ThrowError("Built-in module self-registered.");
return;
}
Expand All @@ -2162,6 +2166,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
} else if (mp->nm_register_func != nullptr) {
mp->nm_register_func(exports, module, mp->nm_priv);
} else {
uv_dlclose(&lib);
env->ThrowError("Module has no declared entry point.");
return;
}
Expand Down

0 comments on commit b196c1d

Please sign in to comment.