fix: free Document only if allocated otherwise treat as static
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m10s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m10s
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user