Skip to content

Guard iAttachment.detach() against an already-released interface (1.x backport of #69) - #78

Open
aminghadersohi wants to merge 1 commit into
FirebirdSQL:release-1.xfrom
aminghadersohi:fix-gc-detach-1.x
Open

aminghadersohi wants to merge 1 commit into
FirebirdSQL:release-1.xfrom
aminghadersohi:fix-gc-detach-1.x

Conversation

@aminghadersohi

Copy link
Copy Markdown

Backport of the #69 fix (#72, merged to master on 2026-05-21) to release-1.x. Fixes #77.

On 1.x, the v5 iAttachment.detach() override calls the native detach without the if self._refcnt: guard that iAttachment_v4.detach() has. When the garbage collector finalizes a connection that was never closed, the interface can already be released, and Connection.__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 in interfaces.py detach in 3 of 3 runs (exit 139)
  • with this change: completed in 3 of 3 runs (exit 0)

The master regression test (tests/test_issues.py::test_issue_69_gc_of_abandoned_connection) relies on the pytest layout, which release-1.x does not have, so it is not ported here. The standalone script in #77 reproduces the crash on this branch.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant