zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 6248e2a5609cb9e30588f8bcd0000f5d5aa5fdee (tree)
parent dc28f5c3ec61a525d45d9f07a666e62f6598ed0a
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat,  1 May 2021 21:25:01 -0700

std.GeneralPurposeAllocator: print leaked memory addresses

This helps when using it with other tools, such as memory watchpoints.

Diffstat:
Mlib/std/heap/general_purpose_allocator.zig | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig @@ -317,7 +317,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { if (is_used) { const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index); const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc); - log.err("Memory leak detected: {s}", .{stack_trace}); + const addr = bucket.page + slot_index * size_class; + log.err("memory address 0x{x} leaked: {s}", .{ + @ptrToInt(addr), stack_trace, + }); leaks = true; } if (bit_index == math.maxInt(u3)) @@ -345,7 +348,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { } var it = self.large_allocations.iterator(); while (it.next()) |large_alloc| { - log.err("Memory leak detected: {s}", .{large_alloc.value.getStackTrace()}); + log.err("memory address 0x{x} leaked: {s}", .{ + @ptrToInt(large_alloc.value.bytes.ptr), large_alloc.value.getStackTrace(), + }); leaks = true; } return leaks;