diff options
author | Keyur <kgovande@etsy.com> | 2016-08-09 17:27:52 +0000 |
---|---|---|
committer | Keyur <kgovande@etsy.com> | 2016-08-09 17:27:52 +0000 |
commit | 2b7715b925c17aaeb6e132a7ce71453f315f2fd1 (patch) | |
tree | c7e3170ed4c0f52e4baf69e424c36f04fbb6a2f5 | |
parent | 842e408c67d5618b90c688b2ee7a5100ab031535 (diff) | |
parent | 2ab9a2d4becfbc8b202fb3a51a1c7664e13838a2 (diff) | |
download | php-git-2b7715b925c17aaeb6e132a7ce71453f315f2fd1.tar.gz |
Merge branch 'pull-request/2067' into PHP-7.0
-rw-r--r-- | ext/pdo/pdo_dbh.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 8a7c1d3931..0f2a2ba788 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -297,7 +297,7 @@ static PHP_METHOD(PDO, dbh_constructor) /* is the connection still alive ? */ if (pdbh->methods->check_liveness && FAILURE == (pdbh->methods->check_liveness)(pdbh)) { /* nope... need to kill it */ - /*??? memory leak */ + pdbh->refcount--; zend_list_close(le); pdbh = NULL; } @@ -310,6 +310,7 @@ static PHP_METHOD(PDO, dbh_constructor) /* need a brand new pdbh */ pdbh = pecalloc(1, sizeof(*pdbh), 1); + pdbh->refcount = 1; pdbh->is_persistent = 1; pdbh->persistent_id = pemalloc(plen + 1, 1); memcpy((char *)pdbh->persistent_id, hashkey, plen+1); @@ -322,6 +323,7 @@ static PHP_METHOD(PDO, dbh_constructor) efree(dbh); /* switch over to the persistent one */ Z_PDO_OBJECT_P(object)->inner = pdbh; + pdbh->refcount++; dbh = pdbh; } @@ -1508,8 +1510,13 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent) dbh->query_stmt = NULL; } - if (dbh->is_persistent && !free_persistent) { - return; + if (dbh->is_persistent) { +#if ZEND_DEBUG + ZEND_ASSERT(!free_persistent || (dbh->refcount == 1)); +#endif + if (!free_persistent && (--dbh->refcount)) { + return; + } } if (dbh->methods) { |