com php-src: Bugfix 72791: fix memory leak in PDO persistent connections: ext/pdo/pdo_dbh.c
| From: | Keyur Govande | Date: | Tue, 09 Aug 2016 14:01:25 +0000 |
| Subject: | com php-src: Bugfix 72791: fix memory leak in PDO persistent connections: ext/pdo/pdo_dbh.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93694@lists.php.net to get a copy of this message | ||
Commit: 98e4d509f67f371b52e476ec252ef7c12b685549
Author: Keyur <kgovande@etsy.com> Tue, 9 Aug 2016 14:01:25 +0000
Parents: 3c5e6b29ce0e0f495a96c7878b23ca00a34c44d7
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=98e4d509f67f371b52e476ec252ef7c12b685549
Log:
Bugfix 72791: fix memory leak in PDO persistent connections
Changed paths:
M ext/pdo/pdo_dbh.c
Diff:
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 8a7c1d3..7a49a03 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) {