[PATCH] lib: add talloc reference from string map iterator to map

Subject: [PATCH] lib: add talloc reference from string map iterator to map

Date: Fri, 23 Sep 2016 06:33:19 -0300

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


This is needed so that when the map is modified during traversal, and
thus unlinked by the database code, the map is not disposed of until the
iterator is done with it.
---

According to my obviously fallible memory, this was always intended to
work something like this. For me, this change fixes the test failures
in T610 on Debian stable.  The same bad behaviour is visible by running
T610/test6 under valgrind even in places where the test passes.

 lib/string-map.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/string-map.c b/lib/string-map.c
index 591ff6d..0bb77e9 100644
--- a/lib/string-map.c
+++ b/lib/string-map.c
@@ -170,6 +170,9 @@ _notmuch_string_map_iterator_create (notmuch_string_map_t *map, const char *key,
     if (unlikely (iter == NULL))
 	return NULL;
 
+    if (unlikely (talloc_reference (iter, map) == NULL))
+	return NULL;
+
     iter->key = talloc_strdup (iter, key);
     iter->exact = exact;
     iter->current = bsearch_first (map->pairs, map->length, key, exact);
-- 
2.1.4


Thread: