Skip to content

Commit

Permalink
Fix resource leak if sqlite open fails
Browse files Browse the repository at this point in the history
We already closed the db on failed attempts but only on two specific
error codes. We'll need to close it no matter what.
  • Loading branch information
pmatilai committed Nov 15, 2024
1 parent 6495cae commit 6707917
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/backend/sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ static int sqlite_init(rpmdb rdb, const char * dbhome)
xx = sqlite3_open_v2(dbfile, &sdb, flags, NULL);
/* Attempt to create if missing, discarding OPEN_READONLY (!) */
if (xx == SQLITE_CANTOPEN && (flags & SQLITE_OPEN_READONLY)) {
/* Sqlite allocates resources even on failure to open (!) */
sqlite3_close(sdb);
flags &= ~SQLITE_OPEN_READONLY;
flags |= (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
retry_open++;
}
if (xx != SQLITE_OK) {
/* Sqlite allocates resources even on failure to open (!) */
sqlite3_close(sdb);
}
}

if (xx != SQLITE_OK) {
Expand Down

0 comments on commit 6707917

Please sign in to comment.