Skip to content

Commit cf3b70d

Browse files
committed
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 phpGH-20213.
1 parent 28ce1b0 commit cf3b70d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ PHP NEWS
4040
. Fixed bug GH-20121 (JIT broken in ZTS builds on MacOS 15).
4141
(Arnaud, Shivam Mathur)
4242

43+
- PgSql:
44+
. Fix memory leak when first string conversion fails. (nielsdos)
45+
4346
- Phar:
4447
. Fix memory leak of argument in webPhar. (nielsdos)
4548
. Fix memory leak when setAlias() fails. (nielsdos)

ext/pgsql/pgsql.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,15 +1057,13 @@ PHP_FUNCTION(pg_query)
10571057

10581058
static void _php_pgsql_free_params(char **params, int num_params)
10591059
{
1060-
if (num_params > 0) {
1061-
int i;
1062-
for (i = 0; i < num_params; i++) {
1063-
if (params[i]) {
1064-
efree(params[i]);
1065-
}
1060+
int i;
1061+
for (i = 0; i < num_params; i++) {
1062+
if (params[i]) {
1063+
efree(params[i]);
10661064
}
1067-
efree(params);
10681065
}
1066+
efree(params);
10691067
}
10701068

10711069
/* Execute a query */

0 commit comments

Comments
 (0)