mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
fs: close dir before throwing if options.bufferSize is invalid
PR-URL: https://github.com/nodejs/node/pull/58856 Fixes: https://github.com/nodejs/node/issues/58854 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
parent
b890c51ff2
commit
9ab976397d
|
|
@ -59,7 +59,13 @@ class Dir {
|
|||
}),
|
||||
};
|
||||
|
||||
validateUint32(this.#options.bufferSize, 'options.bufferSize', true);
|
||||
try {
|
||||
validateUint32(this.#options.bufferSize, 'options.bufferSize', true);
|
||||
} catch (validationError) {
|
||||
// Userland won't be able to close handle if we throw, so we close it first
|
||||
this.#handle.close();
|
||||
throw validationError;
|
||||
}
|
||||
|
||||
this.#readPromisified = FunctionPrototypeBind(
|
||||
promisify(this.#readImpl), this, false);
|
||||
|
|
|
|||
|
|
@ -4,12 +4,20 @@ const common = require('../common');
|
|||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const process = require('node:process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
|
||||
const testDir = tmpdir.path;
|
||||
const files = ['empty', 'files', 'for', 'just', 'testing'];
|
||||
|
||||
process.on('warning', (cause) => {
|
||||
// If any directory handle was left unclosed and then GC'd,
|
||||
// it will emit `Warning: Closing directory handle on garbage collection`.
|
||||
// Treat this warning as error.
|
||||
throw new Error('Expected no warnings', { cause });
|
||||
});
|
||||
|
||||
// Make sure tmp directory is clean
|
||||
tmpdir.refresh();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user