From dbd568c97012d24b6f9c17889879eb7b16221e99 Mon Sep 17 00:00:00 2001 From: laytan Date: Sun, 26 Jul 2026 16:55:22 +0200 Subject: [PATCH] windows bad free fix, print formatting fix, and remove color from tracking allocator results --- core/debug/trace/allocator.odin | 4 ++-- core/debug/trace/trace.odin | 2 ++ core/debug/trace/trace_windows.odin | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/debug/trace/allocator.odin b/core/debug/trace/allocator.odin index 95c61cabb..d6436d684 100644 --- a/core/debug/trace/allocator.odin +++ b/core/debug/trace/allocator.odin @@ -207,7 +207,7 @@ tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, temp_allocator ALLOCATOR_MAX_BACKTRACES :: 16 for _, leak in t.allocation_map { - fmt.eprintfln("\x1b[31m%v leaked %m\x1b[0m", leak.location, leak.size) + fmt.eprintfln("%v leaked %m", leak.location, leak.size) defer i += 1 if i > ALLOCATOR_MAX_BACKTRACES { @@ -230,7 +230,7 @@ tracking_allocator_print_results :: proc(t: ^Tracking_Allocator, temp_allocator for bad_free, _ in t.bad_free_array { fmt.eprintfln( - "\x1b[31m%v allocation %p was freed badly\x1b[0m", + "%v allocation %p was freed badly", bad_free.location, bad_free.memory, ) diff --git a/core/debug/trace/trace.odin b/core/debug/trace/trace.odin index a93dead67..5f86198b4 100644 --- a/core/debug/trace/trace.odin +++ b/core/debug/trace/trace.odin @@ -160,6 +160,8 @@ print :: proc(locations: []Location, padding := "\t") { fmt.eprintf("(%v", location.line) if location.column > 0 { fmt.eprintf(":%v)", location.column) + } else { + fmt.eprint(")") } } else when ODIN_ERROR_POS_STYLE == .Unix { fmt.eprintf(":%v", location.line) diff --git a/core/debug/trace/trace_windows.odin b/core/debug/trace/trace_windows.odin index f78a7c7cd..6f9d1ee89 100644 --- a/core/debug/trace/trace_windows.odin +++ b/core/debug/trace/trace_windows.odin @@ -29,7 +29,9 @@ _capture :: #force_no_inline proc(buf: Capture, skip: int) -> (n: int) { @(private="package") _locations_destroy :: proc(locations: []Location, allocator: runtime.Allocator) { for line in locations { - delete(line.file_path, allocator) + if line.file_path != "??" && line.file_path != OOM_MARKER { + delete(line.file_path, allocator) + } if line.procedure != "??" && line.procedure != OOM_MARKER { delete(line.procedure, allocator) } @@ -98,7 +100,14 @@ _resolve :: proc(bt: Capture, allocator, temp_allocator: runtime.Allocator) -> ( lineInfo.SizeOfStruct = size_of(lineInfo) if win.SymGetLineFromAddrW64(process, win.DWORD64(bt[i]), &{}, &lineInfo) { file_name, mem_err := win.wstring_to_utf8(lineInfo.FileName, len(lineInfo.FileName), allocator) - line.file_path = mem_err == nil ? file_name : OOM_MARKER + if mem_err != nil { + line.file_path = OOM_MARKER + } else if file_name == "??" { + delete(file_name, allocator) + line.file_path = "??" + } else { + line.file_path = file_name + } line.line = i32(lineInfo.LineNumber) } else { location := strings.builder_make(allocator)