]> git.notmuchmail.org Git - notmuch/commitdiff
Prevent segmentation fault in notmuch_database_close
authorJustus Winter <4winter@informatik.uni-hamburg.de>
Sat, 18 Feb 2012 23:56:57 +0000 (00:56 +0100)
committerDavid Bremner <bremner@debian.org>
Tue, 21 Feb 2012 03:03:25 +0000 (23:03 -0400)
Previously opening a notmuch database in read write mode that has been
locked resulted in the notmuch_database_open function executing
notmuch_database_close as a cleanup function. notmuch_database_close
failed to check whether the xapian database has in fact been created.

Add a check whether the xapian database object has actually been
created before trying to call its flush method.

Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
lib/database.cc

index c928d02bb147b039dae529be337dda8055a0b757..5efa85eb162ab47085f4105ebd5b0a0a86f84ddd 100644 (file)
@@ -716,7 +716,8 @@ void
 notmuch_database_close (notmuch_database_t *notmuch)
 {
     try {
-       if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
+       if (notmuch->xapian_db != NULL &&
+           notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
            (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
     } catch (const Xapian::Error &error) {
        if (! notmuch->exception_reported) {