Skip to content

Commit 8a3717c

Browse files
committed
Merge pull request #8991 from MochalovAlexey/eds_transaction_rollback_crash
Fix a possible use-after-free in EDS transaction rollback
1 parent d10a5b0 commit 8a3717c

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/jrd/extds/ExtDS.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,15 +1639,30 @@ void Transaction::rollback(thread_db* tdbb, bool retain)
16391639
doRollback(&status, tdbb, retain);
16401640

16411641
Connection& conn = m_connection;
1642-
if (!retain)
1642+
const bool hasErrors = status->getState() & IStatus::STATE_ERRORS;
1643+
1644+
const auto cleanup = [&]()
16431645
{
1644-
detachFromJrdTran();
1645-
m_connection.deleteTransaction(tdbb, this);
1646-
}
1646+
if (!retain)
1647+
{
1648+
detachFromJrdTran();
1649+
m_connection.deleteTransaction(tdbb, this);
1650+
}
1651+
};
16471652

1648-
if (status->getState() & IStatus::STATE_ERRORS) {
1649-
conn.raise(&status, tdbb, "transaction rollback");
1653+
try
1654+
{
1655+
if (hasErrors) {
1656+
conn.raise(&status, tdbb, "transaction rollback");
1657+
}
1658+
}
1659+
catch (const Exception&)
1660+
{
1661+
cleanup();
1662+
throw;
16501663
}
1664+
1665+
cleanup();
16511666
}
16521667

16531668
Transaction* Transaction::getTransaction(thread_db* tdbb, Connection* conn, TraScope tra_scope)

0 commit comments

Comments
 (0)