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/.

laforge gerrit-no-reply at lists.osmocom.org
Mon Feb 10 10:28:44 UTC 2020


laforge has submitted this change. ( 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(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



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-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200210/c23dcde2/attachment.htm>


More information about the gerrit-log mailing list