authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-01 21:25:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-01 21:25:01-07:00
log6248e2a5609cb9e30588f8bcd0000f5d5aa5fdee
tree2dfead65eabc1cc470ee6146845dcfe2e90ac3de
parentdc28f5c3ec61a525d45d9f07a666e62f6598ed0a

std.GeneralPurposeAllocator: print leaked memory addresses

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

1 files changed, 7 insertions(+), 2 deletions(-)

lib/std/heap/general_purpose_allocator.zig+7-2
...@@ -317,7 +317,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -317,7 +317,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
317 if (is_used) {317 if (is_used) {
318 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);318 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
319 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);319 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
320 log.err("Memory leak detected: {s}", .{stack_trace});320 const addr = bucket.page + slot_index * size_class;
321 log.err("memory address 0x{x} leaked: {s}", .{
322 @ptrToInt(addr), stack_trace,
323 });
321 leaks = true;324 leaks = true;
322 }325 }
323 if (bit_index == math.maxInt(u3))326 if (bit_index == math.maxInt(u3))
...@@ -345,7 +348,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -345,7 +348,9 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
345 }348 }
346 var it = self.large_allocations.iterator();349 var it = self.large_allocations.iterator();
347 while (it.next()) |large_alloc| {350 while (it.next()) |large_alloc| {
348 log.err("Memory leak detected: {s}", .{large_alloc.value.getStackTrace()});351 log.err("memory address 0x{x} leaked: {s}", .{
352 @ptrToInt(large_alloc.value.bytes.ptr), large_alloc.value.getStackTrace(),
353 });
349 leaks = true;354 leaks = true;
350 }355 }
351 return leaks;356 return leaks;