Enhance build options and refactor memory management for configuration parsing

This commit is contained in:
2026-08-02 18:16:58 +02:00
parent 84c4158aaa
commit b1bdfccd1e
2 changed files with 11 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ pub fn main(init: std.process.Init) !void
defer _ = gpa.deinit();
defer if (debug)
{
if (gpa.detectLeaks()) std.posix.exit(1);
if (gpa.detectLeaks() != 0) std.process.exit(1);
};
const allocator = if (debug) gpa.allocator() else std.heap.c_allocator;
@@ -30,8 +30,6 @@ pub fn main(init: std.process.Init) !void
.description = "A lightweight Zig WebSocket server and mesh routing daemon.",
});
var path: []const u8 = undefined;
try parser.addOption("path", .{
.short = 'p',
.help = "Configuration-File Path (*.toml)",
@@ -39,19 +37,19 @@ pub fn main(init: std.process.Init) !void
var result = try parser.parseProcess(init);
if (debug)
const path = if (debug) path:
{
const tmpPath = result.getString("path") orelse "config/config.toml";
path = try allocator.dupe(u8, tmpPath);
break :path try allocator.dupe(u8, tmpPath);
}
else
else path:
{
const tmpPath = result.getString("path") orelse blk: {
const exe = try std.process.executableDirPathAlloc(io, tmpAllocator);
break :blk try std.Io.Dir.path.join(tmpAllocator, &.{ exe, "config/config.toml" });
};
path = try allocator.dupe(u8, tmpPath);
}
break :path try allocator.dupe(u8, tmpPath);
};
tmpArena.deinit();
@@ -71,6 +69,7 @@ fn run(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !void
std.process.exit(1);
};
defer parsed.deinit();
allocator.free(path);
const configuration = parsed.value;