Skip to content

Commit

Permalink
child_process: fix bad abort signal leak
Browse files Browse the repository at this point in the history
Move abort signal validation to before spawn is executed
so that the file is not leaked.

PR-URL: nodejs#37257
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Nitzan Uziely authored and targos committed Aug 8, 2021
1 parent 8862d92 commit 4e1b245
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,11 +875,14 @@ function spawnWithSignal(file, args, options) {
const opts = options && typeof options === 'object' && ('signal' in options) ?
{ ...options, signal: undefined } :
options;
const child = spawn(file, args, opts);

if (options && options.signal) {
if (options?.signal) {
// Validate signal, if present
validateAbortSignal(options.signal, 'options.signal');
}
const child = spawn(file, args, opts);

if (options && options.signal) {
function kill() {
if (child._handle) {
child._handle.kill(options.killSignal || 'SIGTERM');
Expand Down

0 comments on commit 4e1b245

Please sign in to comment.