From 1f93e24a3735a51a9396dbcc659046529019036d Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Sat, 17 Jan 2026 21:42:00 +0100 Subject: [PATCH] fix: free `Document` only if allocated otherwise treat as static --- src/model.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 }; } };