commit 19d7f4dd8221fcd36b7fb71067bf676bb294ca1c (tree)
parent c321b2f2a0257fa45262f1ece0a263b22e8c70f3
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Thu, 23 Jun 2022 17:27:55 -0700
FailingAllocator: Only capture the stack trace of the first induced allocation failure
This is a precaution to avoid confusing stack traces on the off chance that FailingAllocator continues to try to allocate after the first failure.
Diffstat:
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/lib/std/testing/failing_allocator.zig b/lib/std/testing/failing_allocator.zig
@@ -56,13 +56,15 @@ pub const FailingAllocator = struct {
return_address: usize,
) error{OutOfMemory}![]u8 {
if (self.index == self.fail_index) {
- mem.set(usize, &self.stack_addresses, 0);
- var stack_trace = std.builtin.StackTrace{
- .instruction_addresses = &self.stack_addresses,
- .index = 0,
- };
- std.debug.captureStackTrace(return_address, &stack_trace);
- self.has_induced_failure = true;
+ if (!self.has_induced_failure) {
+ mem.set(usize, &self.stack_addresses, 0);
+ var stack_trace = std.builtin.StackTrace{
+ .instruction_addresses = &self.stack_addresses,
+ .index = 0,
+ };
+ std.debug.captureStackTrace(return_address, &stack_trace);
+ self.has_induced_failure = true;
+ }
return error.OutOfMemory;
}
const result = try self.internal_allocator.rawAlloc(len, ptr_align, len_align, return_address);