tdb: don't leak memory in tests.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 24 Aug 2011 03:23:08 +0000 (12:53 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 24 Aug 2011 03:23:08 +0000 (12:53 +0930)
ccan/tdb/test/run-incompatible.c
ccan/tdb/test/run-zero-append.c

index 21f3b21..339d403 100644 (file)
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
 {
        struct tdb_context *tdb;
        unsigned int log_count, flags;
-       TDB_DATA d;
+       TDB_DATA d, r;
        struct tdb_logging_context log_ctx = { log_fn, &log_count };
 
        plan_tests(38 * 2);
@@ -78,7 +78,9 @@ int main(int argc, char *argv[])
                                  O_RDWR, 0600, &log_ctx, NULL);
                ok1(tdb);
                ok1(log_count == 0);
-               ok1(tdb_fetch(tdb, d).dsize == 5);
+               r = tdb_fetch(tdb, d);
+               ok1(r.dsize == 5);
+               free(r.dptr);
                ok1(tdb_check(tdb, NULL, NULL) == 0);
                tdb_close(tdb);
 
@@ -127,7 +129,9 @@ int main(int argc, char *argv[])
                                  O_RDWR, 0600, &log_ctx, tdb_jenkins_hash);
                ok1(tdb);
                ok1(log_count == 0);
-               ok1(tdb_fetch(tdb, d).dsize == 5);
+               r = tdb_fetch(tdb, d);
+               ok1(r.dsize == 5);
+               free(r.dptr);
                ok1(tdb_check(tdb, NULL, NULL) == 0);
                tdb_close(tdb);
 
@@ -137,7 +141,9 @@ int main(int argc, char *argv[])
                                  O_RDWR, 0600, &log_ctx, NULL);
                ok1(tdb);
                ok1(log_count == 0);
-               ok1(tdb_fetch(tdb, d).dsize == 5);
+               r = tdb_fetch(tdb, d);
+               ok1(r.dsize == 5);
+               free(r.dptr);
                ok1(tdb_check(tdb, NULL, NULL) == 0);
                tdb_close(tdb);
 
@@ -170,7 +176,9 @@ int main(int argc, char *argv[])
                                  &log_ctx, tdb_dumb_hash);
                ok1(tdb);
                ok1(log_count == 0);
-               ok1(tdb_fetch(tdb, d).dsize == 5);
+               r = tdb_fetch(tdb, d);
+               ok1(r.dsize == 5);
+               free(r.dptr);
                ok1(tdb_check(tdb, NULL, NULL) == 0);
                tdb_close(tdb);
        }
index 96b0a3e..a869adc 100644 (file)
@@ -36,6 +36,7 @@ int main(int argc, char *argv[])
        data = tdb_fetch(tdb, key);
        ok1(data.dsize == 0);
        tdb_close(tdb);
+       free(data.dptr);
 
        return exit_status();
 }