From f194cdf85231f4f861f6dff7ad8b784e78503f64 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Thu, 8 Jun 2023 22:52:49 +0100 Subject: [PATCH] ext/pgsql: fix PGtrace invalid free issue. disable trace when closing the connection, is a no op if there is no stream attached to it. Close GH-11403 --- NEWS | 3 +++ ext/pgsql/pgsql.c | 1 + ext/pgsql/tests/pg_trace.phpt | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 ext/pgsql/tests/pg_trace.phpt diff --git a/NEWS b/NEWS index f0cbc5a6c97..16dbfb22c3b 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,9 @@ PHP NEWS . Fixed bug GH-9356 Incomplete validation of IPv6 Address fields in subjectAltNames (James Lucas, Jakub Zelenka). +- PGSQL: + . Fixed intermittent segfault with pg_trace. (David Carlier) + - Phar: . Fix cross-compilation check in phar generation for FreeBSD. (peter279k) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index cbed6b7db18..66f09382fc3 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -172,6 +172,7 @@ static void pgsql_link_free(pgsql_link_handle *link) PQclear(res); } if (!link->persistent) { + PQuntrace(link->conn); PQfinish(link->conn); } PGG(num_links)--; diff --git a/ext/pgsql/tests/pg_trace.phpt b/ext/pgsql/tests/pg_trace.phpt new file mode 100644 index 00000000000..89b6027f854 --- /dev/null +++ b/ext/pgsql/tests/pg_trace.phpt @@ -0,0 +1,20 @@ +--TEST-- +pg_trace +--EXTENSIONS-- +pgsql +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true)