File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ PHP NEWS
24
24
- PDO:
25
25
. Fixed bug #72788 (Invalid memory access when using persistent PDO
26
26
connection). (Keyur)
27
+ . Fixed bug #72791 (Memory leak in PDO persistent connection handling). (Keyur)
27
28
28
29
- Reflection:
29
30
. Implemented request #38992 (invoke() and invokeArgs() static method calls
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
@@ -1504,8 +1506,13 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent)
1504
1506
dbh -> query_stmt = NULL ;
1505
1507
}
1506
1508
1507
- if (dbh -> is_persistent && !free_persistent ) {
1508
- return ;
1509
+ if (dbh -> is_persistent ) {
1510
+ #if ZEND_DEBUG
1511
+ ZEND_ASSERT (!free_persistent || (dbh -> refcount == 1 ));
1512
+ #endif
1513
+ if (!free_persistent && (-- dbh -> refcount )) {
1514
+ return ;
1515
+ }
1509
1516
}
1510
1517
1511
1518
if (dbh -> methods ) {
You can’t perform that action at this time.
0 commit comments