Skip to content

Commit 43838c4

Browse files
committed
readline: Fix memory leak in interactive shell INI directive
The readline() buffer is not freed on the #name=value INI-directive branch before continue, unlike the sibling branches. Closes GH-22255
1 parent d70568e commit 43838c4

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

ext/readline/readline_cli.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ static int readline_shell_run(void) /* {{{ */
662662
zend_string_release_ex(prompt, 0);
663663
/* TODO: This might be wrong! */
664664
prompt = cli_get_prompt("php", '>');
665+
free(line);
665666
continue;
666667
}
667668
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Interactive shell: setting an INI directive via #name=value
3+
--EXTENSIONS--
4+
readline
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists('proc_open')) die('skip proc_open() not available');
8+
?>
9+
--FILE--
10+
<?php
11+
$php = getenv('TEST_PHP_EXECUTABLE');
12+
$ini = getenv('TEST_PHP_EXTRA_ARGS');
13+
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
14+
$proc = proc_open("$php $ini -a", $descriptorspec, $pipes);
15+
fwrite($pipes[0], "#precision=5\n");
16+
fwrite($pipes[0], "echo 'INI[' . ini_get('precision') . ']';\n");
17+
fclose($pipes[0]);
18+
proc_close($proc);
19+
?>
20+
--EXPECTF--
21+
%AINI[5]%A

0 commit comments

Comments
 (0)