diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2020-02-09 05:32:46 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2020-02-09 05:32:48 +0700 |
commit | 15ad7bef5ff62965e208d9f6bb9830450085c25f (patch) | |
tree | 6a8de650a8a13f6ff9af1493b1a8d5458b36c0c4 | |
parent | 74e7072f63b2f04cb65b64abfe5ca49695f0166e (diff) |
db: fix possible SQLite3 allocated memory leak in db_open()
From https://sqlite.org/c3ref/exec.html:
To avoid memory leaks, the application should invoke sqlite3_free()
on error message strings returned through the 5th parameter of
sqlite3_exec() after the error message string is no longer needed.
If the 5th parameter to sqlite3_exec() is not NULL and no errors
occur, then sqlite3_exec() sets the pointer in its 5th parameter
to NULL before returning.
Change-Id: Ic9ed9bad3165bc4a637fe963f51e923f012e19ac
Fixes: CID#208182
-rw-r--r-- | src/db.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -535,9 +535,11 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg char *err_msg; rc = sqlite3_exec(dbc->db, "PRAGMA journal_mode=WAL; PRAGMA synchonous = NORMAL;", 0, 0, &err_msg); - if (rc != SQLITE_OK) + if (rc != SQLITE_OK) { LOGP(DDB, LOGL_ERROR, "Unable to set Write-Ahead Logging: %s\n", err_msg); + sqlite3_free(err_msg); + } version = db_get_user_version(dbc); if (version < 0) { |