diff options
| author | Sara Golemon <pollita@php.net> | 2017-10-23 14:44:28 -0400 |
|---|---|---|
| committer | Sara Golemon <pollita@php.net> | 2017-10-23 14:44:28 -0400 |
| commit | 781521e11229da168a7223e9a9829a44788819e1 (patch) | |
| tree | ba096058e267b19e758f09619b57958708ab7943 /ext/pgsql | |
| parent | b07b526b95fc924eeea637907c9ec2b6f6ae970c (diff) | |
| parent | a645af44561acb4696bc9b98a656781ded81fb79 (diff) | |
| download | php-git-781521e11229da168a7223e9a9829a44788819e1.tar.gz | |
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0:
Bugfix#75419 Fix clearing of default link during pg_close()
Diffstat (limited to 'ext/pgsql')
| -rw-r--r-- | ext/pgsql/pgsql.c | 20 | ||||
| -rw-r--r-- | ext/pgsql/tests/bug75419.phpt | 14 |
2 files changed, 21 insertions, 13 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 0fd2e79ecc..8eb80c2c3f 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1568,32 +1568,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; } diff --git a/ext/pgsql/tests/bug75419.phpt b/ext/pgsql/tests/bug75419.phpt new file mode 100644 index 0000000000..09164f4221 --- /dev/null +++ b/ext/pgsql/tests/bug75419.phpt @@ -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) |
