Skip to content

Commit 20465f9

Browse files
committed
Fix GH-21575: Memory leak with notices in pgsql persistent connections.
1 parent 5cd8777 commit 20465f9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ext/pgsql/pgsql.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ static zend_function *pgsql_link_get_constructor(zend_object *object) {
172172
return NULL;
173173
}
174174

175+
static void _php_pgsql_notice_handler(void *l, const char *message);
176+
175177
static void pgsql_link_free(pgsql_link_handle *link)
176178
{
177179
PGresult *res;
@@ -187,6 +189,12 @@ static void pgsql_link_free(pgsql_link_handle *link)
187189

188190
zend_hash_del(&PGG(connections), link->hash);
189191

192+
if (link->persistent) {
193+
/* Reset the notice processor context to NULL so that notices emitted
194+
* during a subsequent PQreset on this persistent PGconn are safely
195+
* ignored rather than written to a stale link handle. */
196+
PQsetNoticeProcessor(link->conn, _php_pgsql_notice_handler, NULL);
197+
}
190198
link->conn = NULL;
191199
zend_string_release(link->hash);
192200

0 commit comments

Comments
 (0)