tdb2: close memory leak in traverse.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)
ccan/tdb2/traverse.c

index 410054d7947a704407dbf3c559a569d22ea27a87..14cdac65148fa05c419f0bd6a514806d99d2fc28 100644 (file)
@@ -26,14 +26,18 @@ static int64_t traverse(struct tdb_context *tdb, int ltype,
        struct tdb_data k, d;
        int64_t count = 0;
 
+       k.dptr = NULL;
        for (ret = first_in_hash(tdb, ltype, &tinfo, &k, &d.dsize);
             ret == 1;
             ret = next_in_hash(tdb, ltype, &tinfo, &k, &d.dsize)) {
                d.dptr = k.dptr + k.dsize;
                
                count++;
-               if (fn && fn(tdb, k, d, p))
+               if (fn && fn(tdb, k, d, p)) {
+                       free(k.dptr);
                        break;
+               }
+               free(k.dptr);
        }
 
        if (ret < 0)