From f2d350e80f3355317de4782cee3de14b60e1e479 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 14 Dec 2024 07:12:45 +0000 Subject: [PATCH] Fix GH-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. --- ext/readline/readline.c | 3 --- ext/readline/tests/gh17154.phpt | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 ext/readline/tests/gh17154.phpt diff --git a/ext/readline/readline.c b/ext/readline/readline.c index 1bd5e2fd6059a..9922925415838 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -74,10 +74,7 @@ ZEND_GET_MODULE(readline) PHP_MINIT_FUNCTION(readline) { -#if HAVE_LIBREADLINE - /* libedit don't need this call which set the tty in cooked mode */ using_history(); -#endif ZVAL_UNDEF(&_readline_completion); #if HAVE_RL_CALLBACK_READ_CHAR ZVAL_UNDEF(&_prepped_callback); diff --git a/ext/readline/tests/gh17154.phpt b/ext/readline/tests/gh17154.phpt new file mode 100644 index 0000000000000..6645855becb6f --- /dev/null +++ b/ext/readline/tests/gh17154.phpt @@ -0,0 +1,12 @@ +--TEST-- +GH-17154 readline_write_history()/readline_read_history(): memory leak +--EXTENSIONS--my +readline +--FILE-- + +--EXPECTF-- +bool(true)