]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Ensure notmuch_query_search_messages returns NULL on an exception.
authorCarl Worth <cworth@cworth.org>
Sat, 24 Apr 2010 14:25:12 +0000 (07:25 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 24 Apr 2010 14:27:50 +0000 (07:27 -0700)
Previously, this function may have segfaulted immediately after
reporting the exception.

lib/notmuch.h
lib/query.cc

index 54616336eabc7e2ac8dede6335e738e81b56d6ed..505ad19fe90470c958fa9d59805af929b588af8e 100644 (file)
@@ -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);
index 7e1b6b52984330d82f6c82462f64d02c2450f0f4..d241dc1dc819a6246e2bfc791330c5448dc9548e 100644 (file)
@@ -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