Commit 1bc1503a540 for php
commit 1bc1503a540bf7638c311762eda9743e0039ea47
Merge: 4bedd96375f 9da12eec011
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date: Mon Nov 2 14:54:21 2026 -0500
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
ext/pdo_pgsql: Clear the notice callback when a persistent handle is released
diff --cc NEWS
index e78542913b0,556548f2c0b..a5211bd3585
--- a/NEWS
+++ b/NEWS
@@@ -167,8 -233,9 +167,11 @@@ PH
out-of-range column index). (Ilia Alshanetsky)
- PDO_PGSQL:
+ . Fixed bug GH-24461 (DISCARD ALL on persistent connection cleanup drops
+ PgBouncer's prepared statements). (David Carlier, Artem Ukrainskiy)
+ . Fixed a use-after-free when a persistent connection receives a notice
+ after the request that called Pdo\Pgsql::setNoticeCallback() has ended.
+ (Ilia Alshanetsky)
- PDO_SQLite:
. Fixed bug GH-24990 (Statement unusable after a failed execute()). (lazerg)
diff --cc ext/pdo_pgsql/pgsql_driver.c
index bdb8a067e61,e69ed9f305c..20edb7f6733
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@@ -1399,33 -1349,11 +1399,35 @@@ static const zend_function_entry *pdo_p
static void pdo_pgsql_request_shutdown(pdo_dbh_t *dbh)
{
+ PGresult *res;
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
- if (H && dbh->refcount <= 2) {
- pdo_pgsql_cleanup_notice_callback(H);
+ if(H->server) {
+ zend_string *name;
+
+ ZEND_HASH_MAP_FOREACH_STR_KEY(H->prepared_stmts, name) {
+#ifndef HAVE_PQCLOSEPREPARED
+ char *q;
+ spprintf(&q, 0, "DEALLOCATE %s", ZSTR_VAL(name));
+ res = PQexec(H->server, q);
+ efree(q);
+#else
+ res = PQclosePrepared(H->server, ZSTR_VAL(name));
+#endif
+ PQclear(res);
+ } ZEND_HASH_FOREACH_END();
+ zend_hash_clean(H->prepared_stmts);
+
+ res = PQexec(H->server, "CLOSE ALL; SET SESSION AUTHORIZATION DEFAULT; RESET ALL; UNLISTEN *; "
+ "SELECT pg_advisory_unlock_all(); DISCARD TEMP; DISCARD SEQUENCES");
+
+ if (PQresultStatus(res) != PGRES_COMMAND_OK && PQstatus(H->server) == CONNECTION_OK) {
+ PQreset(H->server);
+ }
+ PQclear(res);
}
++
++ pdo_pgsql_cleanup_notice_callback(H);
}
static bool pdo_pgsql_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)