From e9e4a1522465ae21ea6568135e4c07378713489e Mon Sep 17 00:00:00 2001 From: Lee Cannon Date: Sun, 26 Jun 2022 01:15:20 +0100 Subject: [PATCH] fix memory leak --- src/main.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 8429e6f..a55e22b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1874,6 +1874,8 @@ pub fn main() anyerror!void { if (!args_it.skip()) @panic("Could not find self argument"); var config_path: ?[]const u8 = null; + defer if (config_path) |path| allocator.free(path); + var next_arg_config_path = false; while (args_it.next()) |arg| { if (next_arg_config_path) { @@ -1913,13 +1915,14 @@ pub fn main() anyerror!void { config_read: { if (config_path) |path| { - defer allocator.free(path); if (loadConfigFile(path)) |conf| { config = conf; break :config_read; } std.debug.print("Could not open configuration file '{s}'\n", .{path}); std.debug.print("Falling back to a lookup in the local and global configuration folders\n", .{}); + allocator.free(path); + config_path = null; } if (try known_folders.getPath(allocator, .local_configuration)) |path| { config_path = path;