summaryrefslogtreecommitdiff
path: root/arena.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-05-15 12:02:56 -0700
committerMichael Pavone <pavone@retrodev.com>2016-05-15 12:02:56 -0700
commit8bf0b4eebf5d06a4daefefcf3d6dd7491c2cd1f9 (patch)
tree64a144f1bd1e59cb621fadd40a1f718e4fe50f81 /arena.c
parent633370ee5f6261d883202ed8690ce801b5b4583c (diff)
Fixed a really egregious bug in the arena implementation. Not sure how this even worked at all before.
Diffstat (limited to 'arena.c')
-rw-r--r--arena.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/arena.c b/arena.c
index 6bc50e0..50a5594 100644
--- a/arena.c
+++ b/arena.c
@@ -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;