diff options
| -rw-r--r-- | src/recent.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/recent.zig b/src/recent.zig index 31ed9c4c..5cccf18b 100644 --- a/src/recent.zig +++ b/src/recent.zig @@ -262,3 +262,21 @@ test "a merge puts this session's changes over the file's list, keeps what is op try std.testing.expect(l.get("/mine").?.open); try std.testing.expect(!l.get("/theirs").?.open); } + +test "a merge that runs out of memory at any allocation leaks nothing" { + var fail_index: usize = 0; + while (fail_index < 64) : (fail_index += 1) { + var failing = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = std.math.maxInt(usize) }); + const gpa = failing.allocator(); + var l: List = .{}; + defer l.deinit(gpa); + l.opened(gpa, "/mine"); + l.opened(gpa, "/kept"); + l.closed(gpa, "/kept", 4, 2, 0, 0); + for (l.entries.items) |*e| e.changed = false; + // From here, the fail_index'th allocation fails. + failing.fail_index = failing.alloc_index + fail_index; + l.merge(gpa, "0 0 0 0 /theirs\n9 1 0 0 /kept\n"); + if (!failing.has_induced_failure) break; + } +} |
