diff options
| author | gingerBill <bill@gingerbill.org> | 2021-09-08 14:45:53 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-09-08 14:45:53 +0100 |
| commit | 76419383a818213ffbd72d08a53ab70716122f8b (patch) | |
| tree | d79b465e471757c758c3f0cd81b9e5ba3816f426 /src/common_memory.cpp | |
| parent | 3aa2924a065a3235ae76cf51e14859739a2d1d0d (diff) | |
Add some minor sanity checks to the compiler's `heap_allocator_proc` on Darwin
Diffstat (limited to 'src/common_memory.cpp')
| -rw-r--r-- | src/common_memory.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/common_memory.cpp b/src/common_memory.cpp index 418470c19..7b4c03a41 100644 --- a/src/common_memory.cpp +++ b/src/common_memory.cpp @@ -379,10 +379,10 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) { break; #else // TODO(bill): *nix version that's decent - case gbAllocation_Alloc: - posix_memalign(&ptr, alignment, size); + case gbAllocation_Alloc: { + int err = posix_memalign(&ptr, alignment, size); gb_zero_size(ptr, size); - break; + } break; case gbAllocation_Free: if (old_memory != nullptr) { @@ -390,13 +390,16 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) { } break; - case gbAllocation_Resize: + case gbAllocation_Resize: { + int err = 0; if (size == 0) { free(old_memory); break; } if (old_memory == nullptr) { - posix_memalign(&ptr, alignment, size); + err = posix_memalign(&ptr, alignment, size); + GB_ASSERT_MSG(err == 0, "posix_memalign err: %d", err); + GB_ASSERT(ptr != nullptr); gb_zero_size(ptr, size); break; } @@ -405,10 +408,14 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) { break; } - posix_memalign(&ptr, alignment, size); + err = posix_memalign(&ptr, alignment, size); + GB_ASSERT_MSG(err == 0, "posix_memalign err: %d", err); + GB_ASSERT(ptr != nullptr); gb_memmove(ptr, old_memory, old_size); - gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0)); - break; + free(old_memory); + isize n = gb_max(size-old_size, 0); + gb_zero_size(cast(u8 *)ptr + old_size, n); + } break; #endif case gbAllocation_FreeAll: |