]> git.cworth.org Git - notmuch/commitdiff
lib/message: check message type before deleting document
authorDavid Bremner <david@tethera.net>
Thu, 20 Jul 2023 12:08:00 +0000 (09:08 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 22 Jul 2023 10:11:46 +0000 (07:11 -0300)
It isn't really clear how this worked before. Traversing the terms of
a document after deleting it from the database seems likely to be
undefined behaviour at best

lib/message.cc

index 53f35dd167fbd1075a452b7cc7e2ed45bae4c4c3..46638f800997d4c5250b3592e4be8ee79abc2a21 100644 (file)
@@ -1397,14 +1397,15 @@ _notmuch_message_delete (notmuch_message_t *message)
        Xapian::PostingIterator thread_doc, thread_doc_end;
        Xapian::PostingIterator mail_doc, mail_doc_end;
 
-       message->notmuch->writable_xapian_db->delete_document (message->doc_id);
-
        /* look for a non-ghost message in the same thread */
        /* if this was a ghost to begin with, we are done */
        private_status = _notmuch_message_has_term (message, "type", "ghost", &is_ghost);
        if (private_status)
            return COERCE_STATUS (private_status,
                                  "Error trying to determine whether message was a ghost");
+
+       message->notmuch->writable_xapian_db->delete_document (message->doc_id);
+
        if (is_ghost)
            return NOTMUCH_STATUS_SUCCESS;