Skip to content

Commit f2d350e

Browse files
committed
Fix phpGH-17154: Memory leak on rl_line_buffer when no history (libedit).
When there is no history, any subsequent history api call initialising it will call rl_initialise() thus we lose the previous value in the process. At module init time, we also call using_history() like with readline.
1 parent e7af08d commit f2d350e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ext/readline/readline.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ ZEND_GET_MODULE(readline)
7474

7575
PHP_MINIT_FUNCTION(readline)
7676
{
77-
#if HAVE_LIBREADLINE
78-
/* libedit don't need this call which set the tty in cooked mode */
7977
using_history();
80-
#endif
8178
ZVAL_UNDEF(&_readline_completion);
8279
#if HAVE_RL_CALLBACK_READ_CHAR
8380
ZVAL_UNDEF(&_prepped_callback);

ext/readline/tests/gh17154.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-17154 readline_write_history()/readline_read_history(): memory leak
3+
--EXTENSIONS--my
4+
readline
5+
--FILE--
6+
<?php
7+
readline_info('line_buffer', 'val');
8+
readline_write_history("myhistory");
9+
var_dump(readline_read_history("myhistory"));
10+
?>
11+
--EXPECTF--
12+
bool(true)

0 commit comments

Comments
 (0)