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/scoped_allocator.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/std/scoped_allocator.c') diff --git a/src/std/scoped_allocator.c b/src/std/scoped_allocator.c index 8b161a1..84ec920 100644 --- a/src/std/scoped_allocator.c +++ b/src/std/scoped_allocator.c @@ -27,7 +27,7 @@ void scoped_allocator_node_deinit(ScopedAllocatorNode *self) { int scoped_allocator_init(ScopedAllocator *self) { return_if_error(scoped_allocator_node_init(&self->head)); self->current = &self->head; - return_if_error(buffer_init(&self->buffers, NULL)); + return_if_error(buffer_init(&self->mems, NULL)); return buffer_init(&self->mutexes, NULL); } @@ -39,15 +39,15 @@ static void buffer_deinit(Buffer *self) { } static void scoped_allocator_deinit_buffers(ScopedAllocator *self) { - Buffer **buffer; - Buffer **buffers_end; - buffer = buffer_begin(&self->buffers); - buffers_end = buffer_end(&self->buffers); - while(buffer != buffers_end) { - buffer_deinit(*buffer); - ++buffer; + void **mem; + void **mems_end; + mem = buffer_begin(&self->mems); + mems_end = buffer_end(&self->mems); + while(mem != mems_end) { + am_free(*mem); + ++mem; } - buffer_deinit(&self->buffers); + buffer_deinit(&self->mems); } static void scoped_allocator_deinit_mutexes(ScopedAllocator *self) { @@ -123,8 +123,11 @@ int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem) { return 0; } -int scoped_allocator_add_buffer(ScopedAllocator *self, Buffer *buffer) { - return buffer_append(&self->buffers, &buffer, sizeof(Buffer*)); +int scoped_allocator_add_mem(ScopedAllocator *self, usize *result_index) { + void *null_data; + null_data = NULL; + *result_index = buffer_get_size(&self->mems, sizeof(void*)); + return buffer_append(&self->mems, &null_data, sizeof(void*)); } int scoped_allocator_create_mutex(ScopedAllocator *self, amal_mutex **mutex) { -- cgit v1.2.3