diff --git a/base/runtime/heap_allocator.odin b/base/runtime/heap_allocator.odin index e2667a78c..4dfe95393 100644 --- a/base/runtime/heap_allocator.odin +++ b/base/runtime/heap_allocator.odin @@ -42,8 +42,10 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, ptr := uintptr(aligned_mem) aligned_ptr := (ptr + uintptr(a)-1) & ~(uintptr(a)-1) if allocated_mem == nil { - aligned_free(old_ptr) - aligned_free(allocated_mem) + // On failure nothing must be freed: heap_resize (realloc) leaves the + // original block intact, and on the copy/fresh path old_ptr has not + // been copied or freed yet. Freeing old_ptr here left the caller's + // pointer dangling, causing a later double free. (#7262) return nil, .Out_Of_Memory }