Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 95ee3b5

Browse filesBrowse files
addaleaxBridgeAR
authored andcommitted
src: use RAII in setgroups implementation
Prefer `MaybeStackBuffer` over manual memory management. PR-URL: #28022 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 1ef2811 commit 95ee3b5
Copy full SHA for 95ee3b5

File tree

Expand file treeCollapse file tree

1 file changed

+2
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+2
-4
lines changed
Open diff view settings
Collapse file

‎src/node_credentials.cc‎

Copy file name to clipboardExpand all lines: src/node_credentials.cc
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,13 @@ static void SetGroups(const FunctionCallbackInfo<Value>& args) {
307307

308308
Local<Array> groups_list = args[0].As<Array>();
309309
size_t size = groups_list->Length();
310-
gid_t* groups = new gid_t[size];
310+
MaybeStackBuffer<gid_t, 64> groups(size);
311311

312312
for (size_t i = 0; i < size; i++) {
313313
gid_t gid = gid_by_name(
314314
env->isolate(), groups_list->Get(env->context(), i).ToLocalChecked());
315315

316316
if (gid == gid_not_found) {
317-
delete[] groups;
318317
// Tells JS to throw ERR_INVALID_CREDENTIAL
319318
args.GetReturnValue().Set(static_cast<uint32_t>(i + 1));
320319
return;
@@ -323,8 +322,7 @@ static void SetGroups(const FunctionCallbackInfo<Value>& args) {
323322
groups[i] = gid;
324323
}
325324

326-
int rc = setgroups(size, groups);
327-
delete[] groups;
325+
int rc = setgroups(size, *groups);
328326

329327
if (rc == -1) return env->ThrowErrnoException(errno, "setgroups");
330328

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.