[evolution-data-server/email-factory] e_dbhash_new: Close and reopen db handle to avoid memory leak



commit d4484c0246aa67b922e8d9a6779d30c3cffc27e3
Author: Christophe Dumez <christophe dumez intel com>
Date:   Mon May 30 14:43:14 2011 +0300

    e_dbhash_new: Close and reopen db handle to avoid memory leak
    
    According to the documentation, "If DB->open fails,
    the DB->close method should be called to discard the DB
    handle". The current code was calling open() again on
    the same handle without closing it it first, possibly
    causing memory leaks.
    
    This patch is adapted from commit
    37d3c0f65c989afe9ffc2d734d86b2ae0019edae in eds-fremantle GIT
    repository.

 libebackend/e-dbhash.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/libebackend/e-dbhash.c b/libebackend/e-dbhash.c
index f720f84..af73b7b 100644
--- a/libebackend/e-dbhash.c
+++ b/libebackend/e-dbhash.c
@@ -34,6 +34,13 @@ e_dbhash_new (const gchar *filename)
 
 	rv = (*db->open) (db, NULL, filename, NULL, DB_HASH, 0, 0666);
 	if (rv != 0) {
+		/* Close and re-create the db handle to avoid memory leak */
+		db->close (db, 0);
+		rv = db_create (&db, NULL, 0);
+		if (rv != 0) {
+			return NULL;
+		}
+
 		rv = (*db->open) (db, NULL, filename, NULL, DB_HASH, DB_CREATE, 0666);
 
 		if (rv != 0) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]