diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-06-27 19:50:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-27 19:50:24 +0200 |
| commit | 9f8b84c2129fb43cd9ede3085e154396593c4ff5 (patch) | |
| tree | 38a6e789a3298c0493783abc1fc396a814be833b | |
| parent | 521182a1007c0a6d372e9a460519983a765849f7 (diff) | |
| parent | 1c199f52d623898dd68405558e9694a6a6fc60a7 (diff) | |
Merge pull request #3815 from laytan/tlsf-fixes
tlsf: destroy first pool & properly zero memory
| -rw-r--r-- | core/mem/tlsf/tlsf.odin | 13 | ||||
| -rw-r--r-- | core/mem/tlsf/tlsf_internal.odin | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/core/mem/tlsf/tlsf.odin b/core/mem/tlsf/tlsf.odin index 76ecbb4b1..8ec5f52b7 100644 --- a/core/mem/tlsf/tlsf.odin +++ b/core/mem/tlsf/tlsf.odin @@ -97,6 +97,10 @@ init :: proc{init_from_buffer, init_from_allocator} destroy :: proc(control: ^Allocator) { if control == nil { return } + if control.pool.allocator.procedure != nil { + runtime.delete(control.pool.data, control.pool.allocator) + } + // No need to call `pool_remove` or anything, as they're they're embedded in the backing memory. // We do however need to free the `Pool` tracking entities and the backing memory itself. // As `Allocator` is embedded in the first backing slice, the `control` pointer will be @@ -132,8 +136,9 @@ allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode, return nil, nil case .Free_All: - clear(control) - return nil, nil + // NOTE: this doesn't work right at the moment, Jeroen has it on his to-do list :) + // clear(control) + return nil, .Mode_Not_Implemented case .Resize: return resize(control, old_memory, uint(old_size), uint(size), uint(alignment)) @@ -144,7 +149,7 @@ allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode, case .Query_Features: set := (^runtime.Allocator_Mode_Set)(old_memory) if set != nil { - set^ = {.Alloc, .Alloc_Non_Zeroed, .Free, .Free_All, .Resize, .Resize_Non_Zeroed, .Query_Features} + set^ = {.Alloc, .Alloc_Non_Zeroed, .Free, /* .Free_All, */ .Resize, .Resize_Non_Zeroed, .Query_Features} } return nil, nil @@ -153,4 +158,4 @@ allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode, } return nil, nil -}
\ No newline at end of file +} diff --git a/core/mem/tlsf/tlsf_internal.odin b/core/mem/tlsf/tlsf_internal.odin index 6f33e516c..9b270d338 100644 --- a/core/mem/tlsf/tlsf_internal.odin +++ b/core/mem/tlsf/tlsf_internal.odin @@ -630,7 +630,7 @@ alloc_bytes_non_zeroed :: proc(control: ^Allocator, size: uint, align: uint) -> @(require_results) alloc_bytes :: proc(control: ^Allocator, size: uint, align: uint) -> (res: []byte, err: runtime.Allocator_Error) { res, err = alloc_bytes_non_zeroed(control, size, align) - if err != nil { + if err == nil { intrinsics.mem_zero(raw_data(res), len(res)) } return @@ -735,4 +735,4 @@ resize_non_zeroed :: proc(control: ^Allocator, ptr: rawptr, old_size, new_size: block_trim_used(control, block, adjust) res = ([^]byte)(ptr)[:new_size] return -}
\ No newline at end of file +} |