aboutsummaryrefslogtreecommitdiff
path: root/src/common_memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common_memory.cpp')
-rw-r--r--src/common_memory.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/common_memory.cpp b/src/common_memory.cpp
index 7b4c03a41..115c58942 100644
--- a/src/common_memory.cpp
+++ b/src/common_memory.cpp
@@ -363,6 +363,9 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
}
break;
}
+
+ alignment = gb_max(alignment, gb_align_of(max_align_t));
+
if (old_memory == nullptr) {
ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1));
gb_zero_size(ptr, size);
@@ -375,12 +378,17 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1));
gb_memmove(ptr, old_memory, old_size);
- gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0));
+ free(old_memory);
+ gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0););
break;
#else
// TODO(bill): *nix version that's decent
case gbAllocation_Alloc: {
- int err = posix_memalign(&ptr, alignment, size);
+ int err = 0;
+ alignment = gb_max(alignment, gb_align_of(max_align_t));
+
+ err = posix_memalign(&ptr, alignment, size);
+ GB_ASSERT_MSG(err == 0, "posix_memalign err: %d", err);
gb_zero_size(ptr, size);
} break;
@@ -396,6 +404,9 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
free(old_memory);
break;
}
+
+ alignment = gb_max(alignment, gb_align_of(max_align_t));
+
if (old_memory == nullptr) {
err = posix_memalign(&ptr, alignment, size);
GB_ASSERT_MSG(err == 0, "posix_memalign err: %d", err);
@@ -413,8 +424,7 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
GB_ASSERT(ptr != nullptr);
gb_memmove(ptr, old_memory, old_size);
free(old_memory);
- isize n = gb_max(size-old_size, 0);
- gb_zero_size(cast(u8 *)ptr + old_size, n);
+ gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0));
} break;
#endif