diff --git a/src/model.zig b/src/model.zig index 555edc4..16a94b1 100644 --- a/src/model.zig +++ b/src/model.zig @@ -26,7 +26,7 @@ pub const Document = struct { title: ?[]const u8 = null, date: ?[]const u8 = null, content: []const u8 = undefined, - ptr: []const u8, + ptr: ?[]const u8, const Preemble = enum { title, @@ -36,7 +36,7 @@ pub const Document = struct { pub const invalidPage: @This() = .{ .title = "Page not found", .content = "Requested page does not exist", - .ptr = undefined, + .ptr = null, }; pub fn init(content: []const u8) @This() { @@ -67,8 +67,8 @@ pub const Document = struct { } pub fn deinit(this: *@This(), allocator: Allocator) void { - allocator.free(this.ptr); - this.* = .{ .ptr = undefined }; + if (this.ptr) |ptr| allocator.free(ptr); + this.* = .{ .ptr = null }; } };