diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-06-02 16:05:31 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-06-06 13:31:58 -0700 |
commit | a8277ddb5505056e3d66d02051c9195310c5c715 (patch) | |
tree | 7fd06375ab937f0b55098af645c751f0644565f1 /src/node_credentials.cc | |
parent | 2976bbd68f936c4f96b6028219ceb9bfc4b84f22 (diff) | |
download | android-node-v8-a8277ddb5505056e3d66d02051c9195310c5c715.tar.gz android-node-v8-a8277ddb5505056e3d66d02051c9195310c5c715.tar.bz2 android-node-v8-a8277ddb5505056e3d66d02051c9195310c5c715.zip |
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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_credentials.cc')
-rw-r--r-- | src/node_credentials.cc | 6 |
1 files changed, 2 insertions, 4 deletions
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<Value>& args) { Local<Array> groups_list = args[0].As<Array>(); size_t size = groups_list->Length(); - gid_t* groups = new gid_t[size]; + MaybeStackBuffer<gid_t, 64> 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<uint32_t>(i + 1)); return; @@ -323,8 +322,7 @@ static void SetGroups(const FunctionCallbackInfo<Value>& args) { groups[i] = gid; } - int rc = setgroups(size, groups); - delete[] groups; + int rc = setgroups(size, *groups); if (rc == -1) return env->ThrowErrnoException(errno, "setgroups"); |