diff options
author | Katharina Fey <kookie@spacekookie.de> | 2019-07-14 18:41:07 +0100 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2019-07-14 18:47:18 +0100 |
commit | f6e83e64abbf76bbfddc90f885f7c3be379ecf2c (patch) | |
tree | 726ff7b647e7cd1704b30638d8adf73c50a15dfe /array.c | |
parent | 98852464c7d4cd3a6a08d0208378506fdce822d6 (diff) |
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 :)
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -12,7 +12,7 @@ err_t array_malloc(struct bowl *self, size_t size) struct bowl_arr *arr = malloc(sizeof(struct bowl_arr)); CHECK(arr, MALLOC_FAILED) - arr->size = 2; + arr->size = size; arr->used = 0; struct bowl **ptr = calloc(sizeof(struct bowl *), arr->size); @@ -109,12 +109,21 @@ err_t array_free(struct bowl *self) struct bowl_arr *arr = self->_pl.array; CHECK(arr, INVALID_STATE) + err_t e; for(int i = 0; i < arr->used; i++) { - err_t e = bowl_free(arr->ptr[i]); + e = bowl_free(arr->ptr[i]); if(e) break; } free(arr->ptr); free(arr); + return e; +} + +err_t array_free_shallow(struct bowl_arr *arr) +{ + CHECK(arr, INVALID_STATE) + free(arr->ptr); + free(arr); return OK; -}
\ No newline at end of file +} |