Skip to content

Commit

Permalink
src: fix uv_err_name memory leak
Browse files Browse the repository at this point in the history
PR-URL: #44421
Refs: #44401
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
  • Loading branch information
theanarkh authored and RafaelGSS committed Sep 7, 2022
1 parent 92046e8 commit 4776b47
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
int err;
if (!args[0]->Int32Value(env->context()).To(&err)) return;
CHECK_LT(err, 0);
const char* name = uv_err_name(err);
char name[50];
uv_err_name_r(err, name, sizeof(name));
args.GetReturnValue().Set(OneByteString(env->isolate(), name));
}

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-uv-errno.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const { internalBinding } = require('internal/test/binding');
const uv = internalBinding('uv');
const keys = Object.keys(uv);

assert.strictEqual(uv.errname(-111111), 'Unknown system error -111111');

keys.forEach((key) => {
if (!key.startsWith('UV_'))
return;
Expand Down

0 comments on commit 4776b47

Please sign in to comment.