summaryrefslogtreecommitdiff
path: root/src/lib/tests
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2023-05-10 11:59:32 +0200
committerSander Vrijders <sander@ouroboros.rocks>2023-05-12 09:58:55 +0200
commitbe3daaf2b7c64f7636981abb0f055aac758e0186 (patch)
tree6c693b92a148c1ec745a5febeda4fdca4832059c /src/lib/tests
parent37535bd29190d013274f4ee100e105ccfd3ace11 (diff)
downloadouroboros-be3daaf2b7c64f7636981abb0f055aac758e0186.tar.gz
ouroboros-be3daaf2b7c64f7636981abb0f055aac758e0186.zip
lib: Fix memleak in bitmap test
There was a missing bmp_destroy, refactored exiting after a failure. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/tests')
-rw-r--r--src/lib/tests/bitmap_test.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/lib/tests/bitmap_test.c b/src/lib/tests/bitmap_test.c
index 8676bfa3..34dcb1a9 100644
--- a/src/lib/tests/bitmap_test.c
+++ b/src/lib/tests/bitmap_test.c
@@ -27,7 +27,8 @@
#define BITMAP_SIZE 200
-int bitmap_test(int argc, char ** argv)
+int bitmap_test(int argc,
+ char ** argv)
{
struct bmp * bmp;
ssize_t bits = BITMAP_SIZE;
@@ -60,27 +61,23 @@ int bitmap_test(int argc, char ** argv)
if (!bmp_is_id_valid(bmp, id)) {
if (i < BITMAP_SIZE + offset) {
printf("Failed valid ID %d (%zd).\n", i, id);
- bmp_destroy(bmp);
- return -1;
+ goto fail;
}
if (id >= offset && id < bits + offset) {
printf("Valid ID %zd returned invalid.\n", id);
- bmp_destroy(bmp);
- return -1;
+ goto fail;
}
continue;
}
if (!bmp_is_id_used(bmp, id)) {
printf("ID not marked in use.\n");
- bmp_destroy(bmp);
- return -1;
+ goto fail;
}
if (id != i) {
printf("Wrong ID returned.\n");
- bmp_destroy(bmp);
- return -1;
+ goto fail;
}
}
@@ -89,20 +86,24 @@ int bitmap_test(int argc, char ** argv)
if (bmp_release(bmp, r)) {
printf("Failed to release ID.\n");
- return -1;
+ goto fail;
}
id = bmp_allocate(bmp);
if (!bmp_is_id_valid(bmp, id))
continue;
+
if (id != r) {
printf("Wrong prev ID returned.\n");
- bmp_destroy(bmp);
- return -1;
+ goto fail;
}
}
bmp_destroy(bmp);
return 0;
+
+ fail:
+ bmp_destroy(bmp);
+ return -1;
}