unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: ukleinek@debian.org
Subject: [PATCH 1/2] lib/message: check message type before deleting document
Date: Thu, 20 Jul 2023 09:08:00 -0300	[thread overview]
Message-ID: <20230720120801.2215538-2-david@tethera.net> (raw)
In-Reply-To: <20230720120801.2215538-1-david@tethera.net>

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 | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 53f35dd1..46638f80 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -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;
 
-- 
2.40.1

  reply	other threads:[~2023-07-20 13:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20 12:07 Speedup for deleting files David Bremner
2023-07-20 12:08 ` David Bremner [this message]
2023-07-20 12:08 ` [PATCH 2/2] lib/n_d_remove_message: do not remove unique filename David Bremner
2023-07-22  9:02 ` Speedup for deleting files Tomi Ollila
2023-08-20 15:56   ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230720120801.2215538-2-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    --cc=ukleinek@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).