diff --git a/core/log/log_allocator.odin b/core/log/log_allocator.odin index e703ee1a9..ea0ec37ba 100644 --- a/core/log/log_allocator.odin +++ b/core/log/log_allocator.odin @@ -36,12 +36,21 @@ log_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode, location = location, ) case .Free: - logf( - level=la.level, - fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%d)", - args = {la.prefix, " " if la.prefix != "" else "", old_memory, old_size}, - location = location, - ) + if old_size != 0 { + logf( + level=la.level, + fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%d)", + args = {la.prefix, " " if la.prefix != "" else "", old_memory, old_size}, + location = location, + ) + } else { + logf( + level=la.level, + fmt_str = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p)", + args = {la.prefix, " " if la.prefix != "" else "", old_memory}, + location = location, + ) + } case .Free_All: logf( level=la.level, diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index 3b8a0fab3..b779ffade 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -143,7 +143,7 @@ free_all :: proc{mem_free_all} @builtin delete_string :: proc(str: string, allocator := context.allocator, loc := #caller_location) -> Allocator_Error { - return mem_free(raw_data(str), allocator, loc) + return mem_free_with_size(raw_data(str), len(str), allocator, loc) } @builtin delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #caller_location) -> Allocator_Error { @@ -151,17 +151,24 @@ delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #cal } @builtin delete_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) -> Allocator_Error { - return mem_free(raw_data(array), array.allocator, loc) + return mem_free_with_size(raw_data(array), cap(array)*size_of(E), array.allocator, loc) } @builtin delete_slice :: proc(array: $T/[]$E, allocator := context.allocator, loc := #caller_location) -> Allocator_Error { - return mem_free(raw_data(array), allocator, loc) + return mem_free_with_size(raw_data(array), len(array)*size_of(E), allocator, loc) } @builtin delete_map :: proc(m: $T/map[$K]$V, loc := #caller_location) -> Allocator_Error { + Entry :: struct { + hash: uintptr, + next: int, + key: K, + value: V, + } + raw := transmute(Raw_Map)m err := delete_slice(raw.hashes, raw.entries.allocator, loc) - err1 := mem_free(raw.entries.data, raw.entries.allocator, loc) + err1 := mem_free_with_size(raw.entries.data, raw.entries.cap*size_of(Entry), raw.entries.allocator, loc) if err == nil { err = err1 } diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 55f600d68..048bff7ca 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -153,6 +153,14 @@ mem_free :: #force_inline proc(ptr: rawptr, allocator := context.allocator, loc return err } +mem_free_with_size :: #force_inline proc(ptr: rawptr, byte_count: int, allocator := context.allocator, loc := #caller_location) -> Allocator_Error { + if ptr == nil || allocator.procedure == nil { + return nil + } + _, err := allocator.procedure(allocator.data, .Free, 0, 0, ptr, byte_count, loc) + return err +} + mem_free_bytes :: #force_inline proc(bytes: []byte, allocator := context.allocator, loc := #caller_location) -> Allocator_Error { if bytes == nil || allocator.procedure == nil { return nil