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,
|
title: ?[]const u8 = null,
|
||||||
date: ?[]const u8 = null,
|
date: ?[]const u8 = null,
|
||||||
content: []const u8 = undefined,
|
content: []const u8 = undefined,
|
||||||
ptr: []const u8,
|
ptr: ?[]const u8,
|
||||||
|
|
||||||
const Preemble = enum {
|
const Preemble = enum {
|
||||||
title,
|
title,
|
||||||
@@ -36,7 +36,7 @@ pub const Document = struct {
|
|||||||
pub const invalidPage: @This() = .{
|
pub const invalidPage: @This() = .{
|
||||||
.title = "Page not found",
|
.title = "Page not found",
|
||||||
.content = "Requested page does not exist",
|
.content = "Requested page does not exist",
|
||||||
.ptr = undefined,
|
.ptr = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(content: []const u8) @This() {
|
pub fn init(content: []const u8) @This() {
|
||||||
@@ -67,8 +67,8 @@ pub const Document = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(this: *@This(), allocator: Allocator) void {
|
pub fn deinit(this: *@This(), allocator: Allocator) void {
|
||||||
allocator.free(this.ptr);
|
if (this.ptr) |ptr| allocator.free(ptr);
|
||||||
this.* = .{ .ptr = undefined };
|
this.* = .{ .ptr = null };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user