File tree 1 file changed +10
-3
lines changed 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -297,7 +297,7 @@ static PHP_METHOD(PDO, dbh_constructor)
297
297
/* is the connection still alive ? */
298
298
if (pdbh -> methods -> check_liveness && FAILURE == (pdbh -> methods -> check_liveness )(pdbh )) {
299
299
/* nope... need to kill it */
300
- /*??? memory leak */
300
+ pdbh -> refcount -- ;
301
301
zend_list_close (le );
302
302
pdbh = NULL ;
303
303
}
@@ -310,6 +310,7 @@ static PHP_METHOD(PDO, dbh_constructor)
310
310
/* need a brand new pdbh */
311
311
pdbh = pecalloc (1 , sizeof (* pdbh ), 1 );
312
312
313
+ pdbh -> refcount = 1 ;
313
314
pdbh -> is_persistent = 1 ;
314
315
pdbh -> persistent_id = pemalloc (plen + 1 , 1 );
315
316
memcpy ((char * )pdbh -> persistent_id , hashkey , plen + 1 );
@@ -322,6 +323,7 @@ static PHP_METHOD(PDO, dbh_constructor)
322
323
efree (dbh );
323
324
/* switch over to the persistent one */
324
325
Z_PDO_OBJECT_P (object )-> inner = pdbh ;
326
+ pdbh -> refcount ++ ;
325
327
dbh = pdbh ;
326
328
}
327
329
@@ -1508,8 +1510,13 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent)
1508
1510
dbh -> query_stmt = NULL ;
1509
1511
}
1510
1512
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
+ }
1513
1520
}
1514
1521
1515
1522
if (dbh -> methods ) {
You can’t perform that action at this time.
0 commit comments