Skip to content

Commit

Permalink
Merge branch 'PHP-7.2'
Browse files Browse the repository at this point in the history
* PHP-7.2:
  Bugfix#75419 Fix clearing of default link during pg_close()
  • Loading branch information
sgolemon committed Oct 23, 2017
2 parents 917dfe6 + ece23ea commit 55ac4f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
20 changes: 7 additions & 13 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1572,32 +1572,26 @@ PHP_FUNCTION(pg_close)
{
zval *pgsql_link = NULL;
zend_resource *link;
int argc = ZEND_NUM_ARGS();
PGconn *pgsql;

if (zend_parse_parameters(argc, "|r", &pgsql_link) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pgsql_link) == FAILURE) {
return;
}

if (argc == 0) {
if (pgsql_link) {
link = Z_RES_P(pgsql_link);
} else {
link = FETCH_DEFAULT_LINK();
CHECK_DEFAULT_LINK(link);
} else {
link = Z_RES_P(pgsql_link);
}

if ((pgsql = (PGconn *)zend_fetch_resource2(link, "PostgreSQL link", le_link, le_plink)) == NULL) {
if (zend_fetch_resource2(link, "PostgreSQL link", le_link, le_plink) == NULL) {
RETURN_FALSE;
}

if (argc == 0) { /* explicit resource number */
zend_list_close(link);
}

if (argc || (pgsql_link && Z_RES_P(pgsql_link) == PGG(default_link))) {
zend_list_close(link);
if (link == PGG(default_link)) {
PGG(default_link) = NULL;
}
zend_list_close(link);

RETURN_TRUE;
}
Expand Down
14 changes: 14 additions & 0 deletions ext/pgsql/tests/bug75419.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Bug #75419 Default link leaked via pg_close()
--SKIPIF--
<?php include("skipif.inc"); ?>
--FILE--
<?php
include('config.inc');

$db1 = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW);
$db2 = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW);
pg_close($db1);
var_dump(pg_ping());
--EXPECT--
bool(true)

0 comments on commit 55ac4f0

Please sign in to comment.