Skip to content

Commit

Permalink
fs: add missing HandleScope to FileHandle.close
Browse files Browse the repository at this point in the history
Fixes: #31202

PR-URL: #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>
  • Loading branch information
addaleax authored and Trott committed Jan 11, 2020
1 parent be055d1 commit 679eb3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/node_file.cc
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-filehandle-close.js
@@ -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());

0 comments on commit 679eb3e

Please sign in to comment.