From a8277ddb5505056e3d66d02051c9195310c5c715 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 2 Jun 2019 16:05:31 +0200 Subject: src: use RAII in setgroups implementation Prefer `MaybeStackBuffer` over manual memory management. PR-URL: https://github.com/nodejs/node/pull/28022 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott --- src/node_credentials.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/node_credentials.cc') diff --git a/src/node_credentials.cc b/src/node_credentials.cc index 6f99cf6641..ad0e1dbb9b 100644 --- a/src/node_credentials.cc +++ b/src/node_credentials.cc @@ -307,14 +307,13 @@ static void SetGroups(const FunctionCallbackInfo& args) { Local groups_list = args[0].As(); size_t size = groups_list->Length(); - gid_t* groups = new gid_t[size]; + MaybeStackBuffer groups(size); for (size_t i = 0; i < size; i++) { gid_t gid = gid_by_name( env->isolate(), groups_list->Get(env->context(), i).ToLocalChecked()); if (gid == gid_not_found) { - delete[] groups; // Tells JS to throw ERR_INVALID_CREDENTIAL args.GetReturnValue().Set(static_cast(i + 1)); return; @@ -323,8 +322,7 @@ static void SetGroups(const FunctionCallbackInfo& args) { groups[i] = gid; } - int rc = setgroups(size, groups); - delete[] groups; + int rc = setgroups(size, *groups); if (rc == -1) return env->ThrowErrnoException(errno, "setgroups"); -- cgit v1.2.3