]> git.ozlabs.org Git - ccan/commitdiff
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 21f3b21a23736e27bd5265ae27e343e572463451..339d40323ccdbaa43de0a3fdeeaebfed35064b7f 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 96b0a3e03bfab437ada5c925de6d7de49ccc35cb..a869adc324c640744a357a0e311f76657c5f4b43 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();
 }