Problem
Database has no destructor that closes db_; the connection is closed only in Finalize(). The constructor (src/database.cc) calls sqlite3_open_v2 and then runs CreateTableQuery::Execute() for every registered record — if any of those throw, the already-opened db_ is leaked (no destructor runs to close it, and instance_ is never assigned).
Impact
- A failure during initialization leaks the SQLite connection.
- Relying on a manual
Finalize() for cleanup is error-prone in general: forgetting it leaks the connection for the process lifetime.
Suggested direction
Give Database a destructor that closes db_ (RAII), and ensure the constructor closes db_ if initialization fails (or wrap the handle in an RAII type), so there is no leak on the error path and cleanup no longer depends on a manual call.
Already addressed (was part of this issue)
The original scope also included a null-check for Instance(). That was implemented in the thread-safety work (#9 / PR #28): Instance() now throws a clear error when the database is not initialized, guarded by the singleton lifecycle mutex. This issue is now scoped to the RAII / leak-on-init-failure concern only.
Problem
Databasehas no destructor that closesdb_; the connection is closed only inFinalize(). The constructor (src/database.cc) callssqlite3_open_v2and then runsCreateTableQuery::Execute()for every registered record — if any of those throw, the already-openeddb_is leaked (no destructor runs to close it, andinstance_is never assigned).Impact
Finalize()for cleanup is error-prone in general: forgetting it leaks the connection for the process lifetime.Suggested direction
Give
Databasea destructor that closesdb_(RAII), and ensure the constructor closesdb_if initialization fails (or wrap the handle in an RAII type), so there is no leak on the error path and cleanup no longer depends on a manual call.Already addressed (was part of this issue)
The original scope also included a null-check for
Instance(). That was implemented in the thread-safety work (#9 / PR #28):Instance()now throws a clear error when the database is not initialized, guarded by the singleton lifecycle mutex. This issue is now scoped to the RAII / leak-on-init-failure concern only.