From: Carl Worth <cworth@cworth.org>
Date: Sat, 24 Apr 2010 14:25:12 +0000 (-0700)
Subject: lib: Ensure notmuch_query_search_messages returns NULL on an exception.
X-Git-Tag: 0.3~71
X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=138fd38afe6c6d44179952dd17c4b07e9223ad37;p=notmuch.git

lib: Ensure notmuch_query_search_messages returns NULL on an exception.

Previously, this function may have segfaulted immediately after
reporting the exception.
---

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 54616336..505ad19f 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -439,6 +439,8 @@ notmuch_query_search_threads (notmuch_query_t *query);
  * notmuch_messages_t object. (For consistency, we do provide a
  * notmuch_messages_destroy function, but there's no good
  * reason to call it if the query is about to be destroyed).
+ *
+ * If a Xapian exception occurs this function will return NULL.
  */
 notmuch_messages_t *
 notmuch_query_search_messages (notmuch_query_t *query);
diff --git a/lib/query.cc b/lib/query.cc
index 7e1b6b52..d241dc1d 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -163,14 +163,16 @@ notmuch_query_search_messages (notmuch_query_t *query)
 	messages->iterator = mset.begin ();
 	messages->iterator_end = mset.end ();
 
+	return &messages->base;
+
     } catch (const Xapian::Error &error) {
 	fprintf (stderr, "A Xapian exception occurred performing query: %s\n",
 		 error.get_msg().c_str());
 	fprintf (stderr, "Query string was: %s\n", query->query_string);
 	notmuch->exception_reported = TRUE;
+	talloc_free (messages);
+	return NULL;
     }
-
-    return &messages->base;
 }
 
 notmuch_bool_t