From b5048ca2997d373c7e9b8938d29c542b891ce970 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 5 Jan 2025 23:27:48 +0200 Subject: remember to free nodes in sptree --- include/conts/sptree.h | 10 ++++++++-- tests/htrie.c | 22 ---------------------- 2 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 tests/htrie.c diff --git a/include/conts/sptree.h b/include/conts/sptree.h index 75b88fc..e305c0f 100644 --- a/include/conts/sptree.h +++ b/include/conts/sptree.h @@ -400,12 +400,18 @@ static inline void SPTREE(remove)(struct SPROOT *s, SPTREE_TYPE data) return; SPTREE(remove_found)(s, found); + struct SPNODE *del = CONTAINER_OF(found, struct SPNODE, data); + free(del); } static inline void SPTREE(destroy)(struct SPROOT *s) { - while (s->root) - SPTREE(remove_found)(s, &s->root->data); + while (s->root) { + SPTREE_TYPE *top = &s->root->data; + SPTREE(remove_found)(s, top); + struct SPNODE *del = CONTAINER_OF(top, struct SPNODE, data); + free(del); + } } #undef SPTREE diff --git a/tests/htrie.c b/tests/htrie.c deleted file mode 100644 index 2c70b38..0000000 --- a/tests/htrie.c +++ /dev/null @@ -1,22 +0,0 @@ -#include - -#define HTRIE_TYPE int -#define HTRIE_KEY int -#define HTRIE_HASH conts_inthash -#define HTRIE_CMP(a, b) ((a) - (b)) -#define HTRIE_NAME ints -#include - -int main() -{ - struct ints ints = ints_create(); - for (int i = 0; i < 1000000; ++i) { - ints_insert(&ints, i, i); - } - - for (int i = 0; i < 1000000; ++i) { - int *v = ints_at(&ints, i); - assert(v && *v == i); - } - ints_destroy(&ints); -} -- cgit v1.2.3