[evolution-data-server/gnome-3-0] e_dbhash_new: Close and reopen db handle to avoid memory leak



commit c422b7050e5d009d3679cddcce479f9dacfbc803
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.
    (cherry picked from commit 6e0731c10801393d2bf1709ccff530df63bdbe28)

 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 7528caf..d51465f 100644
--- a/libebackend/e-dbhash.c
+++ b/libebackend/e-dbhash.c
@@ -50,6 +50,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]