From 1b68fdcf5aebf2bc53bbd9234c77aea243c0decd Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 25 Apr 2019 23:32:23 +0200 Subject: Fix scoped allocator deinit crash with buffers --- src/std/buffer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/std/buffer.c') diff --git a/src/std/buffer.c b/src/std/buffer.c index 5fb4b05..ddf7d39 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -8,9 +8,13 @@ int buffer_init(Buffer *self, struct ScopedAllocator *allocator) { self->data = NULL; self->size = 0; self->capacity = 0; - if(allocator) - return scoped_allocator_add_buffer(allocator, self); - return 0; + self->allocator = allocator; + if(allocator) { + return scoped_allocator_add_mem(allocator, &self->allocator_index); + } else { + self->allocator_index = ~0ULL; + return 0; + } } static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) { @@ -36,6 +40,8 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) self->data = new_mem; self->capacity = capacity; + if(self->allocator) + am_memcpy(self->allocator->mems.data + sizeof(void*) * self->allocator_index, &self->data, sizeof(void*)); return BUFFER_OK; } -- cgit v1.2.3