diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2020-11-10 12:52:13 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2020-12-10 13:28:07 +0200 |
commit | de2b3f139e7c51748e701f7449587c1c10faeaec (patch) | |
tree | 6575fdcc29dc0052b6597a8acb0b4fd5afc4b9dc | |
parent | d8a7e5b36b9fb46488f7e0d6859dbd10fa318ead (diff) | |
download | rpm-de2b3f139e7c51748e701f7449587c1c10faeaec.tar.gz |
Fix a minor memory leak on failed sqlite database open (RhBug:1896301)
Curiously, sqlite allocates resources that need freeing even in case
of failure to open. Quoting from https://www.sqlite.org/c3ref/open.html:
> Whether or not an error occurs when it is opened, resources associated
> with the database connection handle should be released by passing it to
> sqlite3_close() when it is no longer required.
I disagree, but as it's documented behavior there's no point filing a
bug. So lets close the non-open connection and chug on.
(cherry picked from commit fb5888417727edbd8ce1b389b1b6ee9ac899d8e4)
-rw-r--r-- | lib/backend/sqlite.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/backend/sqlite.c b/lib/backend/sqlite.c index ee9c62706..c86697a97 100644 --- a/lib/backend/sqlite.c +++ b/lib/backend/sqlite.c @@ -145,6 +145,8 @@ 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++; |