authorgravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-01-30 01:12:21-06:00
committergravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-01-30 01:12:21-06:00
log9c196efa2afe0e337ac0b16bd1138e89393f6106
treea1323d1b3e1a806fd608a83e86f62f119c7ad52f
parent46d84a1b639eb8e2c11b1936e6897a6352802325

Add explicit error message for too many frees


1 files changed, 3 insertions(+), 0 deletions(-)

lib/std/testing/leak_count_allocator.zig+3
...@@ -33,6 +33,9 @@ pub const LeakCountAllocator = struct {...@@ -33,6 +33,9 @@ pub const LeakCountAllocator = struct {
33 fn shrink(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {33 fn shrink(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {
34 const self = @fieldParentPtr(LeakCountAllocator, "allocator", allocator);34 const self = @fieldParentPtr(LeakCountAllocator, "allocator", allocator);
35 if (new_size == 0) {35 if (new_size == 0) {
36 if (self.count == 0) {
37 std.debug.panic("error - too many calls to free, most likely double free", .{});
38 }
36 self.count -= 1;39 self.count -= 1;
37 }40 }
38 return self.internal_allocator.shrinkFn(self.internal_allocator, old_mem, old_align, new_size, new_align);41 return self.internal_allocator.shrinkFn(self.internal_allocator, old_mem, old_align, new_size, new_align);