summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-08 20:54:12 -0300
committerGabriel Schneider <[email protected]>2026-11-08 21:48:19 -0300
commit3dbd3bbcc7ba00ab4def14dadaf5335e7c566f1e (patch)
tree0e52a488a8533e0adb19c2ff2e5823183b88ab2e
parent2873bf6548d91d997ff436861e64405eb3bc97eb (diff)
downloadpardes-3dbd3bbcc7ba00ab4def14dadaf5335e7c566f1e.tar.gz
pardes-3dbd3bbcc7ba00ab4def14dadaf5335e7c566f1e.zip
fix: the ledger's recent.merge leak on an out-of-memory appendSlice is not one: merge's defer frees every path still in opens on that return; a test fails each of a merge's allocations in turn and testing.allocator finds nothing left, kept as the pin
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/recent.zig18
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;
+ }
+}