From 5633cc6b030139bcd2f03385e83bc9fcf6081127 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. --- ext/pgsql/pgsql.c | 1 + ext/pgsql/tests/pg_trace.phpt | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 ext/pgsql/tests/pg_trace.phpt diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index cbed6b7db18e..66f09382fc32 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 000000000000..89b6027f854e --- /dev/null +++ b/ext/pgsql/tests/pg_trace.phpt @@ -0,0 +1,20 @@ +--TEST-- +pg_trace +--EXTENSIONS-- +pgsql +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true)