diff options
| author | Benjamin Feng <benjamin.feng@glassdoor.com> | 2020-01-30 01:12:21 -0600 |
|---|---|---|
| committer | Benjamin Feng <benjamin.feng@glassdoor.com> | 2020-01-30 01:12:21 -0600 |
| commit | 9c196efa2afe0e337ac0b16bd1138e89393f6106 (patch) | |
| tree | a1323d1b3e1a806fd608a83e86f62f119c7ad52f /lib/std/testing/leak_count_allocator.zig | |
| parent | 46d84a1b639eb8e2c11b1936e6897a6352802325 (diff) | |
| download | zig-9c196efa2afe0e337ac0b16bd1138e89393f6106.tar.gz zig-9c196efa2afe0e337ac0b16bd1138e89393f6106.zip | |
Add explicit error message for too many frees
Diffstat (limited to 'lib/std/testing/leak_count_allocator.zig')
| -rw-r--r-- | lib/std/testing/leak_count_allocator.zig | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/std/testing/leak_count_allocator.zig b/lib/std/testing/leak_count_allocator.zig index 1d65b8c560..65244e529b 100644 --- a/lib/std/testing/leak_count_allocator.zig +++ b/lib/std/testing/leak_count_allocator.zig @@ -33,6 +33,9 @@ pub const LeakCountAllocator = struct { fn shrink(allocator: *std.mem.Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 { const self = @fieldParentPtr(LeakCountAllocator, "allocator", allocator); if (new_size == 0) { + if (self.count == 0) { + std.debug.panic("error - too many calls to free, most likely double free", .{}); + } self.count -= 1; } return self.internal_allocator.shrinkFn(self.internal_allocator, old_mem, old_align, new_size, new_align); |
