Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit ccdac33

Browse files
committed
[[ Bug 22020 ]] Fix memory leak when dbsqlite connection fails
This patch fixes a memory leak which occurs when opening a dbsqlite connection fails. As sqlite3_open will create a connection struct even if there is an error, sqlite3_close must be called regardless of the error returned when opening it.
1 parent c3e607b commit ccdac33

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libsqlite/src/sqlitedataset.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,17 @@ int SqliteDatabase::connect(bool p_use_uri)
426426
return DB_CONNECTION_OK;
427427
}
428428
else
429+
{
430+
/* sqlite3_open will still create a connection object even if there is an
431+
* error - unless it runs out of memory, in which case the connection
432+
* pointer will be nullptr. */
433+
if (conn != nullptr)
434+
{
435+
sqlite3_close(conn);
436+
conn = nullptr;
437+
}
429438
throw DbErrors(getErrorMsg());
439+
}
430440

431441
return DB_CONNECTION_NONE;
432442
};

0 commit comments

Comments
 (0)