Skip to content

Commit 3e512f1

Browse files
addaleaxtargos
authored andcommitted
os: fix memory leak in userInfo()
This previously leaked memory in the ‘success’ case. PR-URL: #23893 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent cc65fee commit 3e512f1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/node_os.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
368368
return args.GetReturnValue().SetUndefined();
369369
}
370370

371+
OnScopeLeave free_passwd([&]() { uv_os_free_passwd(&pwd); });
372+
371373
Local<Value> error;
372374

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

390392
if (username.IsEmpty() || homedir.IsEmpty() || shell.IsEmpty()) {
391393
CHECK(!error.IsEmpty());
392-
uv_os_free_passwd(&pwd);
393394
env->isolate()->ThrowException(error);
394395
return;
395396
}

0 commit comments

Comments
 (0)