Skip to content

Commit 8effbd1

Browse files
committed
PDO: Respect connection transaction state for dtor rollback
As mentioned in bug #80949, if a transaction is implicitly committed, then PDO may still issue a ROLLBACK when the PDO object is destroyed, as the transaction is still marked as active in PDO's (inaccurate) transaction emulation. Make sure we use the connection transaction state also for that final ROLLBACK. A caveat here is that the connection might have been dropped already, which may be the case for some drivers if construction fails. Make sure we don't crash in that case.
1 parent d74c61c commit 8effbd1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent)
14621462
static void pdo_dbh_free_storage(zend_object *std)
14631463
{
14641464
pdo_dbh_t *dbh = php_pdo_dbh_fetch_inner(std);
1465-
if (dbh->in_txn && dbh->methods && dbh->methods->rollback) {
1465+
if (dbh->driver_data && dbh->methods && dbh->methods->rollback && pdo_is_in_transaction(dbh)) {
14661466
dbh->methods->rollback(dbh);
14671467
dbh->in_txn = 0;
14681468
}

0 commit comments

Comments
 (0)