diff options
author | Michael Pavone <pavone@retrodev.com> | 2016-05-15 12:02:56 -0700 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2016-05-15 12:02:56 -0700 |
commit | 8bf0b4eebf5d06a4daefefcf3d6dd7491c2cd1f9 (patch) | |
tree | 64a144f1bd1e59cb621fadd40a1f718e4fe50f81 | |
parent | 633370ee5f6261d883202ed8690ce801b5b4583c (diff) |
Fixed a really egregious bug in the arena implementation. Not sure how this even worked at all before.
-rw-r--r-- | arena.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -17,6 +17,8 @@ struct arena { size_t free_storage; }; +#define DEFAULT_STORAGE_SIZE 8 + static arena *current_arena; arena *get_current_arena() @@ -45,7 +47,11 @@ void track_block(void *block) { arena *cur = get_current_arena(); if (cur->used_count == cur->used_storage) { - cur->used_storage *= 2; + if (cur->used_storage) { + cur->used_storage *= 2; + } else { + cur->used_storage = DEFAULT_STORAGE_SIZE; + } cur->used_blocks = realloc(cur->used_blocks, cur->used_storage * sizeof(void *)); } cur->used_blocks[cur->used_count++] = block; |