8000 Process: close process handles · symfony/symfony@454ce55 · GitHub
[go: up one dir, main page]

Skip to content

Commit 454ce55

Browse files
committed
Process: close process handles
1 parent 38c3583 commit 454ce55

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,14 @@ public static function isTtySupported(): bool
12551255
static $isTtySupported;
12561256

12571257
if (null === $isTtySupported) {
1258-
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
1258+
$handle = @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
1259+
$isTtySupported = (bool) $handle;
1260+
if (false !== $handle) {
1261+
fclose($pipes[0]);
1262+
fclose($pipes[1]);
1263+
fclose($pipes[2]);
1264+
proc_close($handle);
1265+
}
12591266
}
12601267

12611268
return $isTtySupported;
@@ -1278,7 +1285,16 @@ public static function isPtySupported()
12781285
return $result = false;
12791286
}
12801287

1281-
return $result = (bool) @proc_open('echo 1 >/dev/null', [['pty'], ['pty'], ['pty']], $pipes);
1288+
$handle = @proc_open('echo 1 >/dev/null', [['pty'], ['pty'], ['pty']], $pipes);
1289+
$result = (bool) $handle;
1290+
if (false !== $handle) {
1291+
fclose($pipes[0]);
1292+
fclose($pipes[1]);
1293+
fclose($pipes[2]);
1294+
proc_close($handle);
1295+
}
1296+
1297+
return $result;
12821298
}
12831299

12841300
/**
@@ -1517,8 +1533,12 @@ private function doSignal(int $signal, bool $throwException): bool
15171533
$ok = @proc_terminate($this->process, $signal);
15181534
} elseif (\function_exists('posix_kill')) {
15191535
$ok = @posix_kill($pid, $signal);
1520-
} elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
1536+
} elseif ($handle = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
15211537
$ok = false === fgets($pipes[2]);
1538+
fclose($pipes[2]);
1539+
proc_close($handle);
1540+
} else {
1541+
$ok = false;
15221542
}
15231543
if (!$ok) {
15241544
if ($throwException) {

0 commit comments

Comments
 (0)
0