From 2ca3a65d9c338d4cebdce28fe773c38703492411 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. --- ext/pgsql/pgsql.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 1d7fee6017004..e8fb99c7aca46 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 */