mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-21162: pg_connect() on error memory leak.
This commit is contained in:
@@ -706,10 +706,12 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
|
||||
/* create the link */
|
||||
pgsql = PQconnectdb(connstring);
|
||||
if (pgsql == NULL || PQstatus(pgsql) == CONNECTION_BAD) {
|
||||
PHP_PQ_ERROR("Unable to connect to PostgreSQL server: %s", pgsql)
|
||||
zend_string *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql));
|
||||
if (pgsql) {
|
||||
PQfinish(pgsql);
|
||||
}
|
||||
php_error_docref(NULL, E_WARNING, "Unable to connect to PostgreSQL server: %s", ZSTR_VAL(msgbuf));
|
||||
zend_string_release(msgbuf);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -790,19 +792,23 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
|
||||
if (connect_type & PGSQL_CONNECT_ASYNC) {
|
||||
pgsql = PQconnectStart(connstring);
|
||||
if (pgsql==NULL || PQstatus(pgsql)==CONNECTION_BAD) {
|
||||
PHP_PQ_ERROR("Unable to connect to PostgreSQL server: %s", pgsql);
|
||||
zend_string *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql));
|
||||
if (pgsql) {
|
||||
PQfinish(pgsql);
|
||||
}
|
||||
php_error_docref(NULL, E_WARNING, "Unable to connect to PostgreSQL server: %s", ZSTR_VAL(msgbuf));
|
||||
zend_string_release(msgbuf);
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
pgsql = PQconnectdb(connstring);
|
||||
if (pgsql==NULL || PQstatus(pgsql)==CONNECTION_BAD) {
|
||||
PHP_PQ_ERROR("Unable to connect to PostgreSQL server: %s", pgsql);
|
||||
zend_string *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql));
|
||||
if (pgsql) {
|
||||
PQfinish(pgsql);
|
||||
}
|
||||
php_error_docref(NULL, E_WARNING, "Unable to connect to PostgreSQL server: %s", ZSTR_VAL(msgbuf));
|
||||
zend_string_release(msgbuf);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
18
ext/pgsql/tests/gh21162.phpt
Normal file
18
ext/pgsql/tests/gh21162.phpt
Normal file
@@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
GH-21162 (pg_connect() on error memory leak)
|
||||
--EXTENSIONS--
|
||||
pgsql
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
set_error_handler(function (int $errno, string $errstr) {
|
||||
echo "Warning caught\n";
|
||||
});
|
||||
|
||||
pg_connect('');
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
Warning caught
|
||||
Done
|
||||
Reference in New Issue
Block a user