From 1d0c4f82e5130e3d125b20ebd5a9dc7d3789f6f1 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 26 Oct 2018 09:08:56 +0200 Subject: [PATCH 1/2] 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. --- src/node_os.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_os.cc b/src/node_os.cc index d3e9460f473122..cee4535915b40f 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -360,6 +360,7 @@ static void GetUserInfo(const FunctionCallbackInfo& args) { } const int err = uv_os_get_passwd(&pwd); + OnScopeLeave free_passwd([&]() { uv_os_free_passwd(&pwd); }); if (err) { CHECK_GE(args.Length(), 2); @@ -389,7 +390,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; } From 21e0e8657d68e9ee38a9c1826f97ffc918504ea5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 26 Oct 2018 09:41:03 +0200 Subject: [PATCH 2/2] fixup! os: fix memory leak in `userInfo()` --- 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 cee4535915b40f..723cf18b3efd27 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -360,7 +360,6 @@ static void GetUserInfo(const FunctionCallbackInfo& args) { } const int err = uv_os_get_passwd(&pwd); - OnScopeLeave free_passwd([&]() { uv_os_free_passwd(&pwd); }); if (err) { CHECK_GE(args.Length(), 2); @@ -369,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);