Close connection immediately after failed open - #719
Conversation
This is required per the documentation, otherwise can result in memory leaks due to unfreed resources.
|
@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. |
|
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.
|
The story here is that I did not encounter this problem per se. I was making a similar fix for Elixir driver and checked how other drivers (Ruby, Python) handle this. I found out that Ruby has a similar problem as Elixir and decided to make a PR here as well. |
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.