std.GeneralPurposeAllocator: print leaked memory addresses

This helps when using it with other tools, such as memory watchpoints.
This commit is contained in:
Andrew Kelley 2021-05-01 21:25:01 -07:00
parent dc28f5c3ec
commit 6248e2a560

View File

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