X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=16c4354f2448bbc39bff3a1c3f630b4775575cd4;hp=c928d02bb147b039dae529be337dda8055a0b757;hb=ea54c4fdc7d0ed9a4d6ab328d44c10ce5668d587;hpb=d43f6c00b351424e903c2f2b71c34bc5902b467e diff --git a/lib/database.cc b/lib/database.cc index c928d02b..16c4354f 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -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 (notmuch->xapian_db))->flush (); } catch (const Xapian::Error &error) { if (! notmuch->exception_reported) { @@ -725,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; @@ -1813,6 +1825,9 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch, if (message_ret == NULL) return NOTMUCH_STATUS_NULL_POINTER; + /* return NULL on any failure */ + *message_ret = NULL; + local = talloc_new (notmuch); try {