From: David Bremner <david@tethera.net>
To: "Olivier Taïbi" <oli@olitb.net>, notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH] lib/config: don't set destructor until iterator is initialized.
Date: Thu, 29 Oct 2020 21:19:10 -0300 [thread overview]
Message-ID: <20201030001910.939645-1-david@tethera.net> (raw)
In-Reply-To: <20201027100916.emry3k2wujod4xnl@galois.lan>
As diagnosed by Olivier Taïbi in
id:20201027100916.emry3k2wujod4xnl@galois.lan, if an exception is
thrown while the initialization is happening (e.g. if the function is
called on a closed database), then the destructor is (sometimes)
invoked on an uninitialized Xapian object.
Solve the problem by moving the setting of the destructor until after
the placement new successfully completes. It is conceivable this might
cause a memory leak, but that seems preferable to crashing, and in any
case, there seems to be nothing better to be done if the
initialization is failing things are in an undefined state by
definition.
---
lib/config.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/config.cc b/lib/config.cc
index dae0ff0e..efab01e4 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -113,7 +113,6 @@ notmuch_database_get_config_list (notmuch_database_t *notmuch,
goto DONE;
}
- talloc_set_destructor (list, _notmuch_config_list_destroy);
list->notmuch = notmuch;
list->current_key = NULL;
list->current_val = NULL;
@@ -122,6 +121,7 @@ notmuch_database_get_config_list (notmuch_database_t *notmuch,
new(&(list->iterator)) Xapian::TermIterator (notmuch->xapian_db->metadata_keys_begin
(CONFIG_PREFIX + (prefix ? prefix : "")));
+ talloc_set_destructor (list, _notmuch_config_list_destroy);
} catch (const Xapian::Error &error) {
_notmuch_database_log (notmuch, "A Xapian exception occurred getting metadata iterator: %s.\n",
--
2.28.0\r
next prev parent reply other threads:[~2020-10-30 0:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 10:09 segfault in T590-libconfig notmuch_database_get_config_list: closed db Olivier Taïbi
2020-10-28 11:21 ` David Bremner
2020-10-30 0:19 ` David Bremner [this message]
2020-10-31 17:49 ` [PATCH] lib/config: don't set destructor until iterator is initialized 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=20201030001910.939645-1-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
--cc=oli@olitb.net \
/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).