Guard iAttachment.detach() against an already-released interface (1.x backport of #69) - #78
Open
aminghadersohi wants to merge 1 commit into
Open
aminghadersohi wants to merge 1 commit into
aminghadersohi wants to merge 1 commit into
Conversation
Backport of the FirebirdSQL#69 fix (FirebirdSQL#72) to release-1.x. During cyclic garbage collection the iAttachment's own iReferenceCounted.__del__ may run release() before Connection.__del__ calls detach(); the v5 detach() override then dereferenced freed memory and segfaulted. Restore the if self._refcnt guard that iAttachment_v4.detach() already has. Fixes FirebirdSQL#77.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of the #69 fix (#72, merged to
masteron 2026-05-21) torelease-1.x. Fixes #77.On 1.x, the v5
iAttachment.detach()override calls the nativedetachwithout theif self._refcnt:guard thatiAttachment_v4.detach()has. When the garbage collector finalizes a connection that was never closed, the interface can already be released, andConnection.__del__then detaches freed memory, which segfaults the process.The change restores the guard, the same code as on
master.Verification against Firebird 5.0.3, CPython 3.11.15, Linux x86_64, with firebird-base 1.8.0, using the reproduction script in #77 (100 abandoned connections, each followed by
gc.collect()):release-1.x(1.10.11): segfault ininterfaces.pydetachin 3 of 3 runs (exit 139)The master regression test (
tests/test_issues.py::test_issue_69_gc_of_abandoned_connection) relies on the pytest layout, whichrelease-1.xdoes not have, so it is not ported here. The standalone script in #77 reproduces the crash on this branch.