[PATCH] Actually close the xapian database in notmuch_database_close

Justus Winter 4winter at informatik.uni-hamburg.de
Fri Mar 2 06:58:39 PST 2012


Formerly the xapian database object was deleted and closed in its
destructor once the object was garbage collected. Explicitly call
close() so that the database and the associated lock is released
immediately.

The comment is a courtesy of Austin Clements.

Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de>
---
 lib/database.cc |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 5efa85e..8f8df1a 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -726,6 +726,17 @@ notmuch_database_close (notmuch_database_t *notmuch)
 	}
     }
 
+    /* Many Xapian objects (and thus notmuch objects) hold references to
+     * the database, so merely deleting the database may not suffice to
+     * close it.  Thus, we explicitly close it here. */
+    if (notmuch->xapian_db != NULL) {
+	try {
+	    notmuch->xapian_db->close();
+	} catch (const Xapian::Error &error) {
+	    /* do nothing */
+	}
+    }
+
     delete notmuch->term_gen;
     delete notmuch->query_parser;
     delete notmuch->xapian_db;
-- 
1.7.9.1



More information about the notmuch mailing list