Skip to content

Commit 2b7715b

Browse files
committed
Merge branch 'pull-request/2067' into PHP-7.0
2 parents 842e408 + 2ab9a2d commit 2b7715b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static PHP_METHOD(PDO, dbh_constructor)
297297
/* is the connection still alive ? */
298298
if (pdbh->methods->check_liveness && FAILURE == (pdbh->methods->check_liveness)(pdbh)) {
299299
/* nope... need to kill it */
300-
/*??? memory leak */
300+
pdbh->refcount--;
301301
zend_list_close(le);
302302
pdbh = NULL;
303303
}
@@ -310,6 +310,7 @@ static PHP_METHOD(PDO, dbh_constructor)
310310
/* need a brand new pdbh */
311311
pdbh = pecalloc(1, sizeof(*pdbh), 1);
312312

313+
pdbh->refcount = 1;
313314
pdbh->is_persistent = 1;
314315
pdbh->persistent_id = pemalloc(plen + 1, 1);
315316
memcpy((char *)pdbh->persistent_id, hashkey, plen+1);
@@ -322,6 +323,7 @@ static PHP_METHOD(PDO, dbh_constructor)
322323
efree(dbh);
323324
/* switch over to the persistent one */
324325
Z_PDO_OBJECT_P(object)->inner = pdbh;
326+
pdbh->refcount++;
325327
dbh = pdbh;
326328
}
327329

@@ -1508,8 +1510,13 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent)
15081510
dbh->query_stmt = NULL;
15091511
}
15101512

1511-
if (dbh->is_persistent && !free_persistent) {
1512-
return;
1513+
if (dbh->is_persistent) {
1514+
#if ZEND_DEBUG
1515+
ZEND_ASSERT(!free_persistent || (dbh->refcount == 1));
1516+
#endif
1517+
if (!free_persistent && (--dbh->refcount)) {
1518+
return;
1519+
}
15131520
}
15141521

15151522
if (dbh->methods) {

0 commit comments

Comments
 (0)