aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-06 12:58:14 +0800
committerMistivia <i@mistivia.com>2025-06-06 12:58:14 +0800
commit1fad3a10fe4743d69342de294cc65bfe66e32bc9 (patch)
treed91be066e44fe7af1eeece0f1b081463bc64dfc7 /tests
parent4779050053cb5f73b54ff936c6393e82ffe5605c (diff)
fix leak and hashtable bug
Diffstat (limited to 'tests')
-rw-r--r--tests/test_augment_rbtree.c2
-rw-r--r--tests/test_htable.c1
-rw-r--r--tests/test_pque.c1
-rw-r--r--tests/test_rbtree.c2
-rw-r--r--tests/test_str.c7
5 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_augment_rbtree.c b/tests/test_augment_rbtree.c
index 0389405..9ee3921 100644
--- a/tests/test_augment_rbtree.c
+++ b/tests/test_augment_rbtree.c
@@ -113,6 +113,7 @@ static void test_largedata() {
IntIntEntry *iter = rb_tree_find(&tree, &input[i]);
assert(iter != NULL);
rb_tree_remove(&tree, iter);
+ free(iter);
}
// check tree validity
d = depth(tree.rbh_root);
@@ -126,4 +127,5 @@ static void test_largedata() {
assert(iter->key == i * 3);
i++;
}
+ destroy_rb_tree(&tree, NULL);
}
diff --git a/tests/test_htable.c b/tests/test_htable.c
index 310d141..77413d3 100644
--- a/tests/test_htable.c
+++ b/tests/test_htable.c
@@ -66,6 +66,7 @@ int main() {
for (int i = 0; i < 10000; i++) {
assert(found[i]);
}
+ destroy_hash_table(&ht);
printf("[PASS] htable\n");
}
diff --git a/tests/test_pque.c b/tests/test_pque.c
index 01e6e1c..a6565bd 100644
--- a/tests/test_pque.c
+++ b/tests/test_pque.c
@@ -35,6 +35,7 @@ int main() {
int *top = priority_queue_top(&pq);
assert(*top == expected[i]);
}
+ free(pq.buf);
printf("[PASS] pque\n");
return 0;
}
diff --git a/tests/test_rbtree.c b/tests/test_rbtree.c
index b1fbc32..e001d9b 100644
--- a/tests/test_rbtree.c
+++ b/tests/test_rbtree.c
@@ -115,6 +115,7 @@ static void test_largedata() {
IntIntEntry *iter = rb_tree_find(&tree, &input[i]);
assert(iter != NULL);
rb_tree_remove(&tree, iter);
+ free(iter);
}
// check tree validity
d = depth(tree.rbh_root);
@@ -125,4 +126,5 @@ static void test_largedata() {
assert(iter->key == i * 3);
i++;
}
+ destroy_rb_tree(&tree, NULL);
}
diff --git a/tests/test_str.c b/tests/test_str.c
index 85e4f31..bde028e 100644
--- a/tests/test_str.c
+++ b/tests/test_str.c
@@ -61,24 +61,31 @@ void test_str_strip() {
s = str_strip("hello ");
assert(strcmp(s, "hello") == 0);
+ free(s);
s = str_strip("hello");
assert(strcmp(s, "hello") == 0);
+ free(s);
s = str_strip("\nhello ");
assert(strcmp(s, "hello") == 0);
+ free(s);
s = str_strip("\nhello");
assert(strcmp(s, "hello") == 0);
+ free(s);
s = str_strip("");
assert(strcmp(s, "") == 0);
+ free(s);
s = str_strip("\n\t ");
assert(strcmp(s, "") == 0);
+ free(s);
s = str_strip(" ");
assert(strcmp(s, "") == 0);
+ free(s);
}
void test_str_bulider() {