From f6e83e64abbf76bbfddc90f885f7c3be379ecf2c Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Sun, 14 Jul 2019 18:41:07 +0100 Subject: Various improvements around HASH nodes The example previously would lead to corrupt memory when running for items that needed to re-hash the hash array. This has been fixed. Secondly, all HASH node memory leaks are now fixed, that resulted from badly tracking objects through the resize process. A new function `hash_free_shallow` was added to help with this. The function `array_free_shallow` is unused but might become useful in the future and so was not removed. The hash strategy is still garbage but this can be fixed later :) --- bowl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'bowl.c') diff --git a/bowl.c b/bowl.c index e515f6b..248ac37 100644 --- a/bowl.c +++ b/bowl.c @@ -31,7 +31,7 @@ err_t bowl_malloc(struct bowl **ptr, bowl_t type) switch((*ptr)->type) { case LEAF: return OK; // No further allocation needed - case ARRAY: return array_malloc(*ptr, ARRAY_START_SIZE); + case ARRAY | HASH: return array_malloc(*ptr, ARRAY_START_SIZE); default: return INVALID_STATE; } @@ -139,7 +139,8 @@ err_t bowl_free(struct bowl *self) err_t e; switch(self->type) { case LEAF: e = data_free(self->_pl.data); break; - case ARRAY | HASH: e = array_free(self); break; + case ARRAY: e = array_free(self); break; + case HASH: e = hash_free(self); break; default: e = INVALID_STATE; break; } if(e) return e; -- cgit v1.2.3