Skip to content

Commit 4e1b245

Browse files
Nitzan Uzielytargos
authored andcommitted
child_process: fix bad abort signal leak
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>
1 parent 8862d92 commit 4e1b245

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/child_process.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,14 @@ function spawnWithSignal(file, args, options) {
875875
const opts = options && typeof options === 'object' && ('signal' in options) ?
876876
{ ...options, signal: undefined } :
877877
options;
878-
const child = spawn(file, args, opts);
879878

880-
if (options && options.signal) {
879+
if (options?.signal) {
881880
// Validate signal, if present
882881
validateAbortSignal(options.signal, 'options.signal');
882+
}
883+
const child = spawn(file, args, opts);
884+
885+
if (options && options.signal) {
883886
function kill() {
884887
if (child._handle) {
885888
child._handle.kill(options.killSignal || 'SIGTERM');

0 commit comments

Comments
 (0)