- /*
+ /*
Trivial Database 2: traverse function.
Copyright (C) Rusty Russell 2010
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
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)
default:
return tdb_null;
}
-}
+}
/* We lock twice, not very efficient. We could keep last key & tinfo cached. */
TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key)
default:
return tdb_null;
}
-}
+}