linux-edac.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ras-record: fix memory leak when sqlite3_open_v2 fails
@ 2020-11-09 12:49 lvying6
  0 siblings, 0 replies; only message in thread
From: lvying6 @ 2020-11-09 12:49 UTC (permalink / raw)
  To: mchehab+huawei, linux-edac; +Cc: fanwentao

According to SQLite documentation, a database connection handle
is usually returned, even if an error occurs. This behavior has
caused rasdaemon to leak memory when opening a database is failed. Now,
even if sqlite3_open_v2() does not return SQLITE_OK, rasdaemon tries to
release SQLite database handle by calling sqlite3_close_v2().

Signed-off-by: lvying6 <lvying6@huawei.com>
---
 ras-record.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ras-record.c b/ras-record.c
index 549c494..dc89f01 100644
--- a/ras-record.c
+++ b/ras-record.c
@@ -726,6 +726,8 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras)
 	} while (rc == SQLITE_BUSY);
 
 	if (rc != SQLITE_OK) {
+		sqlite3_close_v2(db);
+		db = NULL;
 		log(TERM, LOG_ERR,
 		    "cpu %u: Failed to connect to %s: error = %d\n",
 		    cpu, SQLITE_RAS_DB, rc);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-09 12:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 12:49 [PATCH] ras-record: fix memory leak when sqlite3_open_v2 fails lvying6

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).