From c9781111e1d22b45ebdee294aa679240b6fd41de Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 24 May 2025 16:17:43 +0200 Subject: [PATCH] Fix memory leak when calloc() fails in php_readline_completion_cb() Closes GH-18637. --- NEWS | 4 ++++ ext/readline/readline.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index a8d6d6ee6fe..fc7e534d604 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ PHP NEWS - Phar: . Add missing filter cleanups on phar failure. (nielsdos) +- Readline: + . Fix memory leak when calloc() fails in php_readline_completion_cb(). + (nielsdos) + 05 Jun 2025, PHP 8.3.22 - Core: diff --git a/ext/readline/readline.c b/ext/readline/readline.c index 1bd5e2fd605..4da9f359515 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -458,13 +458,14 @@ char **php_readline_completion_cb(const char *text, int start, int end) /* libedit will read matches[2] */ matches = calloc(3, sizeof(char *)); if (!matches) { - return NULL; + goto out; } matches[0] = strdup(""); } } } +out: zval_ptr_dtor(¶ms[0]); zval_ptr_dtor(&_readline_array);