From cf3b70d23cdf6f09f6e605d17295e671c76dee84 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 18 Oct 2025 11:41:49 +0200 Subject: [PATCH] pgsql: Fix memory leak when first string conversion fails If the first string conversion fails, then i==0, but memory was still allocated for `params`. However, we skip freeing `params` when i==0. Closes GH-20213. --- NEWS | 3 +++ ext/pgsql/pgsql.c | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 96dd99d8da8..537673e64fa 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,9 @@ PHP NEWS . Fixed bug GH-20121 (JIT broken in ZTS builds on MacOS 15). (Arnaud, Shivam Mathur) +- PgSql: + . Fix memory leak when first string conversion fails. (nielsdos) + - Phar: . Fix memory leak of argument in webPhar. (nielsdos) . Fix memory leak when setAlias() fails. (nielsdos) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 1d7fee60170..e8fb99c7aca 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1057,15 +1057,13 @@ PHP_FUNCTION(pg_query) static void _php_pgsql_free_params(char **params, int num_params) { - if (num_params > 0) { - int i; - for (i = 0; i < num_params; i++) { - if (params[i]) { - efree(params[i]); - } + int i; + for (i = 0; i < num_params; i++) { + if (params[i]) { + efree(params[i]); } - efree(params); } + efree(params); } /* Execute a query */