Fix segfault when closing cursor/connection after Statement.free()#67
Open
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
Open
Fix segfault when closing cursor/connection after Statement.free()#67fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
fdcastel wants to merge 1 commit intoFirebirdSQL:masterfrom
Conversation
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.
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.
Summary
DatabaseError: Invalid resultset interface) when closing a cursor or connection after the associatedStatementhas already been freed via context manager or explicitfree()call.Cursor._clear()unconditionally calledself._result.close()on theIResultSet, even when the parentStatementhad already been freed — operating on an invalidated Firebird interface.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.tests/conftest.pywhere--client-libpassed aPathinstead ofstrtodriver_config.fb_client_library.value.Test plan
test_issue_65_prepare_ctx_mgr— Statement freed viawithcontext manager, then cursor closestest_issue_65_free_then_cursor_close— Explicitstmt.free()followed bycursor.close()test_issue_65_free_then_conn_close—stmt.free()followed by connection close (triggers cursor close via transaction rollback)