Change in osmo-hlr[master]: db: fix possible SQLite3 allocated memory leak in db_open()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Sat Feb 8 22:34:26 UTC 2020


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hlr/+/17112 )


Change subject: db: fix possible SQLite3 allocated memory leak in db_open()
......................................................................

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
---
M src/db.c
1 file changed, 3 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/12/17112/1

diff --git a/src/db.c b/src/db.c
index 5e5ad35..9d0c621 100644
--- a/src/db.c
+++ b/src/db.c
@@ -535,9 +535,11 @@
 
 	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) {

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-hlr/+/17112
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Change-Id: Ic9ed9bad3165bc4a637fe963f51e923f012e19ac
Gerrit-Change-Number: 17112
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200208/d851594c/attachment.htm>


More information about the gerrit-log mailing list