Close connection immediately after failed open#719
Merged
flavorjones merged 2 commits intoJul 16, 2026
Conversation
This is required per the documentation, otherwise can result in memory leaks due to unfreed resources.
Member
|
@katafrakt Thanks for the PR. Reading the docs, this does sound like the right thing to do. Can I ask how you ran into this? Is there an easy way to reproduce the underlying failure conditions? I'd like to try to write a test and run it under valgrind/ASan to make sure memory leaks are all quashed. |
Member
|
Ah - ignore my question, I see it's as easy as opening a nonexistent file. I'll try to put a test around this, but the change itself seems fine. Thanks! Worth noting: in the current codebase the memory is eventually cleaned up when the object is GCed, but this change would make that cleanup happen immediately which is definitely better. |
Specifically I want valgrind to be checking for correctness. Also add a changelog entry.
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.
Per documentation
sqlite3_close_v2should be called to free up resources even aftersqlite3_open(and family) fails:This is a bit verbose, because we need to get the message before closing and pass to
CHECK_MSG. Alternative would be to keep usingCHECK, but then a generic message would be printed.