aboutsummaryrefslogtreecommitdiff
path: root/src/std/buffer.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-04-25 23:32:23 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit1b68fdcf5aebf2bc53bbd9234c77aea243c0decd (patch)
tree1a26f5b5ab32e6b435fa2afca789a5b846d11f46 /src/std/buffer.c
parent7f524c427597cc998f243769b0e22e4f450c55cf (diff)
Fix scoped allocator deinit crash with buffers
Diffstat (limited to 'src/std/buffer.c')
-rw-r--r--src/std/buffer.c12
1 files changed, 9 insertions, 3 deletions
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;
}