summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Dumez <christophe.dumez@intel.com>2011-05-30 14:43:14 +0300
committerPatrick Ohly <patrick.ohly@intel.com>2011-06-07 10:53:08 +0200
commitc422b7050e5d009d3679cddcce479f9dacfbc803 (patch)
tree66e8a5262316bd1f894d30675d2b5b733af740b7
parent5fd8caaa1b3b279ffac41e837dae0a1bcc2489cc (diff)
downloadevolution-data-server-c422b7050e5d009d3679cddcce479f9dacfbc803.tar.gz
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)
-rw-r--r--libebackend/e-dbhash.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libebackend/e-dbhash.c b/libebackend/e-dbhash.c
index 7528cafb4..d51465f91 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) {