unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] lib/config: delay setting talloc destructor
@ 2020-08-05  0:56 David Bremner
  0 siblings, 0 replies; only message in thread
From: David Bremner @ 2020-08-05  0:56 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

If Xapian has thrown an exception, it is not safe to invoke the
destuctor when freeing the list struct.
---

this is a latent exception handling bug I missed before. It showed up
when updating some config related code, but I guess we were just lucky(?)
before. The bug manifests as one of the tests in T590-libconfig failing.

 lib/config.cc | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/config.cc b/lib/config.cc
index f5def3aa..ca7ac2a8 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;
@@ -133,8 +132,15 @@ notmuch_database_get_config_list (notmuch_database_t *notmuch,
     *out = list;
 
   DONE:
-    if (status && list)
-	talloc_free (list);
+    if (status) {
+	if (list) {
+	    talloc_free (list);
+	    if (status != NOTMUCH_STATUS_XAPIAN_EXCEPTION)
+		_notmuch_config_list_destroy (list);
+	}
+    }  else {
+	talloc_set_destructor (list, _notmuch_config_list_destroy);
+    }
 
     return status;
 }
-- 
2.27.0

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-05  0:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-05  0:56 [PATCH] lib/config: delay setting talloc destructor David Bremner

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).