diff options
| author | rationalcoder <rationalcoder@gmail.com> | 2025-09-16 16:31:10 -0500 |
|---|---|---|
| committer | rationalcoder <rationalcoder@gmail.com> | 2025-09-16 16:31:10 -0500 |
| commit | 710533975e6da554b943bc24fb6e38ba22fe959a (patch) | |
| tree | 712468d3c479b0be84086c9a6bb7785f227905f5 /core/mem | |
| parent | 11be0cb4ab41c52591a90ca07e7a04062487369e (diff) | |
Fix out-of-band allocations in dynamic arenas
Diffstat (limited to 'core/mem')
| -rw-r--r-- | core/mem/allocators.odin | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin index 59fe72fbb..5b0b178f8 100644 --- a/core/mem/allocators.odin +++ b/core/mem/allocators.odin @@ -1819,18 +1819,18 @@ memory region. */ @(require_results) dynamic_arena_alloc_bytes_non_zeroed :: proc(a: ^Dynamic_Arena, size: int, loc := #caller_location) -> ([]byte, Allocator_Error) { - n := align_formula(size, a.alignment) - if n > a.block_size { - return nil, .Invalid_Argument - } - if n >= a.out_band_size { - assert(a.block_allocator.procedure != nil, "Backing block allocator must be initialized", loc=loc) - memory, err := alloc_bytes_non_zeroed(a.block_size, a.alignment, a.block_allocator, loc) + if size >= a.out_band_size { + assert(a.out_band_allocations.allocator.procedure != nil, "Backing array allocator must be initialized", loc=loc) + memory, err := alloc_bytes_non_zeroed(size, a.alignment, a.out_band_allocations.allocator, loc) if memory != nil { append(&a.out_band_allocations, raw_data(memory), loc = loc) } return memory, err } + n := align_formula(size, a.alignment) + if n > a.block_size { + return nil, .Invalid_Argument + } if a.bytes_left < n { err := _dynamic_arena_cycle_new_block(a, loc) if err != nil { @@ -1867,7 +1867,7 @@ dynamic_arena_reset :: proc(a: ^Dynamic_Arena, loc := #caller_location) { } clear(&a.used_blocks) for allocation in a.out_band_allocations { - free(allocation, a.block_allocator, loc=loc) + free(allocation, a.out_band_allocations.allocator, loc=loc) } clear(&a.out_band_allocations) a.bytes_left = 0 // Make new allocations call `_dynamic_arena_cycle_new_block` again. |