Skip to content

Fix segfault when closing cursor/connection after Statement.free()#67

Open
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
fdcastel:fix-issue-65
Open

Fix segfault when closing cursor/connection after Statement.free()#67
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
fdcastel:fix-issue-65

Conversation

@fdcastel
Copy link
Copy Markdown
Member

Summary

  • Fixes Segmentation fault when close connection or cursor. #65 — segfault (or DatabaseError: Invalid resultset interface) when closing a cursor or connection after the associated Statement has already been freed via context manager or explicit free() call.
  • Root cause: Cursor._clear() unconditionally called self._result.close() on the IResultSet, even when the parent Statement had already been freed — operating on an invalidated Firebird interface.
  • Fix: In Cursor._clear(), check whether the statement's interface (_istmt) is still valid before closing the result set. If the statement was already freed, safely discard the result set reference instead.
  • Also fixes a minor bug in tests/conftest.py where --client-lib passed a Path instead of str to driver_config.fb_client_library.value.

Test plan

  • test_issue_65_prepare_ctx_mgr — Statement freed via with context manager, then cursor closes
  • test_issue_65_free_then_cursor_close — Explicit stmt.free() followed by cursor.close()
  • test_issue_65_free_then_conn_closestmt.free() followed by connection close (triggers cursor close via transaction rollback)
  • All existing cursor and statement tests pass (23/23)

FirebirdSQL#65.

When a Statement was freed (via context manager or explicit free()) before
its Cursor was closed, Cursor._clear() would attempt to close an already-
invalidated IResultSet, causing a segfault or DatabaseError.

Now checks whether the Statement's interface is still valid before closing
the result set. If the statement was already freed, the result set reference
is safely discarded instead.
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.

Segmentation fault when close connection or cursor.

1 participant