Skip to content

Commit

Permalink
os: fix memory leak in userInfo()
Browse files Browse the repository at this point in the history
This previously leaked memory in the ‘success’ case.

PR-URL: #23893
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and danbev committed Oct 31, 2018
1 parent 6f4721b commit d690a87
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().SetUndefined();
}

OnScopeLeave free_passwd([&]() { uv_os_free_passwd(&pwd); });

Local<Value> error;

Local<Value> uid = Number::New(env->isolate(), pwd.uid);
Expand All @@ -389,7 +391,6 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {

if (username.IsEmpty() || homedir.IsEmpty() || shell.IsEmpty()) {
CHECK(!error.IsEmpty());
uv_os_free_passwd(&pwd);
env->isolate()->ThrowException(error);
return;
}
Expand Down

0 comments on commit d690a87

Please sign in to comment.