From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 6B2FC6DE02C9 for ; Fri, 23 Sep 2016 03:13:58 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5 tests=[AWL=-0.002, HEADER_FROM_DIFFERENT_DOMAINS=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Kmoo8k8FYAOE for ; Fri, 23 Sep 2016 03:13:56 -0700 (PDT) X-Greylist: delayed 2416 seconds by postgrey-1.35 at arlo; Fri, 23 Sep 2016 03:13:56 PDT Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 91C936DE0008 for ; Fri, 23 Sep 2016 03:13:56 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1bnMrF-0000DL-8F; Fri, 23 Sep 2016 05:33:25 -0400 Received: (nullmailer pid 4219 invoked by uid 1000); Fri, 23 Sep 2016 09:33:32 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH] lib: add talloc reference from string map iterator to map Date: Fri, 23 Sep 2016 06:33:19 -0300 Message-Id: <1474623199-4150-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Sep 2016 10:13:58 -0000 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