windows bad free fix, print formatting fix, and remove color from tracking allocator results

This commit is contained in:
laytan
2026-07-26 16:55:22 +02:00
parent ed0166bd16
commit dbd568c970
3 changed files with 15 additions and 4 deletions

View File

@@ -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,
)

View File

@@ -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)

View File

@@ -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)