From d690a87b8c71208a021cbcc21b09d27007c0f9dd Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 26 Oct 2018 09:08:56 +0200 Subject: [PATCH] os: fix memory leak in `userInfo()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This previously leaked memory in the ‘success’ case. PR-URL: https://github.com/nodejs/node/pull/23893 Reviewed-By: Michaël Zasso Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: James M Snell --- src/node_os.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_os.cc b/src/node_os.cc index 6e209b2ceec71c..486192a506108e 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -368,6 +368,8 @@ static void GetUserInfo(const FunctionCallbackInfo& args) { return args.GetReturnValue().SetUndefined(); } + OnScopeLeave free_passwd([&]() { uv_os_free_passwd(&pwd); }); + Local error; Local uid = Number::New(env->isolate(), pwd.uid); @@ -389,7 +391,6 @@ static void GetUserInfo(const FunctionCallbackInfo& args) { if (username.IsEmpty() || homedir.IsEmpty() || shell.IsEmpty()) { CHECK(!error.IsEmpty()); - uv_os_free_passwd(&pwd); env->isolate()->ThrowException(error); return; }