diff --git a/lib/notmuch.h b/lib/notmuch.h index 505ad19f..9a196999 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -400,6 +400,8 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort); * notmuch_threads_t object. (For consistency, we do provide a * notmuch_threads_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_threads_t * notmuch_query_search_threads (notmuch_query_t *query); diff --git a/lib/query.cc b/lib/query.cc index d241dc1d..59f4011b 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -249,6 +249,10 @@ notmuch_query_search_threads (notmuch_query_t *query) free, NULL); threads->messages = notmuch_query_search_messages (query); + if (threads->messages == NULL) { + talloc_free (threads); + return NULL; + } threads->thread_id = NULL;