0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00

fs: add missing HandleScope to FileHandle.close

Fixes: https://github.com/nodejs/node/issues/31202

PR-URL: https://github.com/nodejs/node/pull/31276
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Anna Henningsen 2020-01-09 11:24:23 +01:00 committed by Rich Trott
parent be055d103c
commit 679eb3e7d5
2 changed files with 18 additions and 0 deletions

View File

@ -301,6 +301,7 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
close->file_handle()->AfterClose();
Isolate* isolate = close->env()->isolate();
if (req->result < 0) {
HandleScope handle_scope(isolate);
close->Reject(UVException(isolate, req->result, "close"));
} else {
close->Resolve();

View File

@ -0,0 +1,17 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
// Test that using FileHandle.close to close an already-closed fd fails
// with EBADF.
(async function() {
const fh = await fs.promises.open(__filename);
fs.closeSync(fh.fd);
assert.rejects(() => fh.close(), {
code: 'EBADF',
syscall: 'close'
});
})().then(common.mustCall());