Skip to content

Commit bfa4af4

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #39663 (Memory leak in pg_get_notify() and a possible memory
corruption on Windows in pgsql and pdo_pgsql extensions).
1 parent 60bb494 commit bfa4af4

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ PHP NEWS
4545
- Added optimization for imageline with horizontal and vertial lines (Pierre)
4646
- Fixed bug #39673 (file_get_contents causes bus error on certain offsets).
4747
(Tony)
48+
- Fixed bug #39663 (Memory leak in pg_get_notify() and a possible memory
49+
corruption on Windows in pgsql and pdo_pgsql extensions). (Ilia, matteo at
50+
beccati dot com)
4851
- Fixed bug #39662 (Segfault when calling asXML() of a cloned SimpleXMLElement).
4952
(Rob, Tony)
5053
- Fixed bug #39656 (crash when calling fetch() on a PDO statment object

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
325325
(*quoted)[0] = '\'';
326326
(*quoted)[*quotedlen-1] = '\'';
327327
(*quoted)[*quotedlen] = '\0';
328-
free(escaped);
328+
PQfreemem(escaped);
329329
break;
330330
default:
331331
*quoted = safe_emalloc(2, unquotedlen, 3);

ext/pgsql/pgsql.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ PHP_FUNCTION(pg_copy_to)
33583358
break;
33593359
default:
33603360
add_next_index_string(return_value, csv, 1);
3361-
free(csv);
3361+
PQfreemem(csv);
33623362
break;
33633363
}
33643364
}
@@ -3610,7 +3610,7 @@ PHP_FUNCTION(pg_escape_bytea)
36103610
to = (char *)PQescapeBytea((unsigned char*)from, from_len, &to_len);
36113611

36123612
RETVAL_STRINGL(to, to_len-1, 1); /* to_len includes addtional '\0' */
3613-
free(to);
3613+
PQfreemem(to);
36143614
}
36153615
/* }}} */
36163616

@@ -3735,7 +3735,7 @@ PHP_FUNCTION(pg_unescape_bytea)
37353735
#if HAVE_PQUNESCAPEBYTEA
37363736
tmp = (char *)PQunescapeBytea((unsigned char*)from, &to_len);
37373737
to = estrndup(tmp, to_len);
3738-
free(tmp);
3738+
PQfreemem(tmp);
37393739
#else
37403740
to = (char *)php_pgsql_unescape_bytea((unsigned char*)from, &to_len);
37413741
#endif
@@ -4348,6 +4348,7 @@ PHP_FUNCTION(pg_get_notify)
43484348
add_assoc_string(return_value, "message", pgsql_notify->relname, 1);
43494349
add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
43504350
}
4351+
PQfreemem(pgsql_notify);
43514352
}
43524353
/* }}} */
43534354

@@ -5153,7 +5154,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
51535154
Z_STRLEN_P(new_val) = to_len-1; /* PQescapeBytea's to_len includes additional '\0' */
51545155
Z_STRVAL_P(new_val) = emalloc(to_len);
51555156
memcpy(Z_STRVAL_P(new_val), tmp, to_len);
5156-
free(tmp);
5157+
PQfreemem(tmp);
51575158
php_pgsql_add_quotes(new_val, 1 TSRMLS_CC);
51585159

51595160
}

0 commit comments

Comments
 (0)