Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › heap › SafeAllocator › deinitLeakedBucket Private Function deinitLeakedBucket Doc Source Private Function std.heap.SafeAllocator.deinitLeakedBucket
fn deinitLeakedBucket (s : *SafeAllocator , b : *Bucket , log : bool ) usize Params File heap/SafeAllocator.zig: 688
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727 fn deinitLeakedBucket (s : *SafeAllocator , b : *Bucket , log : bool ) usize {
var leaks : usize = 0 ;
const expected = @atomicLoad (Bucket .AllocCount , &b .alloc_count , .acquire );
if (expected .n == 0 ) assert (expected .filling );
var footer = b .lastAlloc (s , b .fill ).?;
while (true ) {
const modify = @atomicRmw (
AllocFooter .Modify ,
&footer .modify ,
.Xchg ,
undefined ,
.monotonic ,
).storedXor (&footer .modify );
const bad_modify = modify != .none and modify != .freed ;
if (bad_modify or footer .actualChecksum (s ) != footer .checksum ^ s .canary ) {
panic ("corrupted footer metadata in bucket at *{x}" , .{@intFromPtr (&footer )});
}
switch (modify ) {
.none => {
leaks += 1 ;
if (log ) scoped_log .err ("leaked {f} allocated at: {f}" , .{ FormatMemory {
.memory = footer .userMemory (),
.alignment = footer .userAlign (),
}, formatStackTrace (footer .allocTrace (s )) });
},
.freed => s .checkFreed (footer ),
else => unreachable ,
}
footer = footer .bucketPrev (b , s ) orelse break ;
}
s .backing .rawFree (b .bytes (s ), @fromBackingInt (@intCast (s .bucket_size_log2 )), 0 );
assert (leaks == expected .n );
return leaks ;
}
Returns the true count of leaks