diff options
Diffstat (limited to 'core/dump.zig')
| -rw-r--r-- | core/dump.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/dump.zig b/core/dump.zig index 4bb89dae..8e44d82d 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -400,6 +400,9 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: errdefer { if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {}; l.rollback(); + // Its opens are what the load read: the rollback's, freed (and + // their count may be a damaged one, refused). + p.fs.opens_len = 0; p.fs.deinit(gpa); gpa.destroy(p); } @@ -476,6 +479,9 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* errdefer { if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {}; l.rollback(); + // Its opens are what the load read: the rollback's, freed (and + // their count may be a damaged one, refused). + p.fs.opens_len = 0; p.fs.deinit(gpa); gpa.destroy(p); } @@ -1418,3 +1424,20 @@ test "optional GPU addon reload generation survives a replica dump" { try std.testing.expectEqual(original.gen, restored.gen); try std.testing.expectEqual(walk.digest(Kind.Slot, &original), walk.digest(Kind.Slot, &restored)); } + +test "a load refused after the core frees what a script's open held once: the rollback's, not the namespace's" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .mounts = &.{.{ .name = "peer", .dial = "/tmp/peer.sock" }} }); + defer p.deinit(); + _ = try p.setTestFile("x\n"); + // A script's open of a file of command lines, its last line half + // written: bytes the load makes. + p.fs.opens[0] = .{ .node = 1, .what = .lines }; + try p.fs.opens[0].pending.appendSlice(gpa, "Look half"); + p.fs.opens_len = 1; + const bytes = try byteDump(p); + defer gpa.free(bytes); + // The mounts are read after the core: the same name dialled elsewhere + // refuses the load there. + try std.testing.expectError(error.MountConflict, load(gpa, .{ .mounts = &.{.{ .name = "peer", .dial = "/tmp/other.sock" }} }, bytes, null)); +} |
