Skip to content

Commit 5961626

Browse files
addaleaxcodebytere
authored andcommitted
fs: add missing HandleScope to FileHandle.close
Fixes: #31202 PR-URL: #31276 Reviewed-By: David Carlier <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 40b5e0e commit 5961626

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/node_file.cc

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
301301
close->file_handle()->AfterClose();
302302
Isolate* isolate = close->env()->isolate();
303303
if (req->result < 0) {
304+
HandleScope handle_scope(isolate);
304305
close->Reject(UVException(isolate, req->result, "close"));
305306
} else {
306307
close->Resolve();
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const fs = require('fs');
5+
6+
// Test that using FileHandle.close to close an already-closed fd fails
7+
// with EBADF.
8+
9+
(async function() {
10+
const fh = await fs.promises.open(__filename);
11+
fs.closeSync(fh.fd);
12+
13+
assert.rejects(() => fh.close(), {
14+
code: 'EBADF',
15+
syscall: 'close'
16+
});
17+
})().then(common.mustCall());

0 commit comments

Comments
 (0)