---
 lib/open.cc | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/open.cc b/lib/open.cc
index 463e38bf..5470ea23 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -434,6 +434,15 @@ _load_database_state (notmuch_database_t *notmuch)
        notmuch, notmuch->xapian_db->get_uuid ().c_str ());
 }
 
+static int
+_index_as_text_free (regex_t *regexv)
+{
+    size_t num_regex = talloc_get_size (regexv) / sizeof (*regexv);
+    for (size_t i = 0; i < num_regex; i++)
+       regfree (&regexv[i]);
+    return 0;
+}
+
 /* XXX This should really be done lazily, but the error reporting path in the 
indexing code
  * would need to be redone to report any errors.
  */
@@ -460,6 +469,9 @@ _ensure_index_as_text (notmuch_database_t *notmuch, char 
**message)
        assert (len > 0);
 
        regexv = talloc_realloc (notmuch, regexv, regex_t, nregex + 1);
+       if (nregex == 0)
+           talloc_set_destructor (regexv, _index_as_text_free);
+
        new_regex = &regexv[nregex];
 
        rerr = regcomp (new_regex, str, REG_EXTENDED | REG_NOSUB);
-- 
2.47.3

_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to