From 74556479db84b4ff93aa2515ff00918ecef1d69d Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Sun, 31 Dec 2023 15:48:36 +0100 Subject: [PATCH] Fix some bugs (hopefully) Signed-off-by: AnErrupTion --- src/main.zig | 12 +++++++++--- src/tui/components/Desktop.zig | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4f7fcb1..960f41e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -80,6 +80,9 @@ pub fn main() !void { } // Initialize information line with host name + var got_host_name = false; + var host_name_buffer: []u8 = undefined; + get_host_name: { const host_name_struct = interop.getHostName(allocator) catch |err| { if (err == error.CannotGetHostName) { @@ -89,8 +92,9 @@ pub fn main() !void { } break :get_host_name; }; - defer allocator.free(host_name_struct.buffer); + got_host_name = true; + host_name_buffer = host_name_struct.buffer; info_line = host_name_struct.slice; } @@ -134,14 +138,14 @@ pub fn main() !void { const reader = file.reader(); const username_length = try reader.readIntLittle(u64); - const username_buffer = try file.readToEndAlloc(allocator, username_length); + const username_buffer = try reader.readAllAlloc(allocator, username_length); defer allocator.free(username_buffer); _ = try reader.read(username_buffer); const current_desktop = try reader.readIntLittle(u64); - const load_buffer = try file.readToEndAlloc(allocator, config.ly.max_login_len + 5); + const load_buffer = try reader.readAllAlloc(allocator, config.ly.max_login_len + 5); defer allocator.free(load_buffer); if (username_buffer.len > 0) { @@ -509,6 +513,8 @@ pub fn main() !void { } } + if (got_host_name) allocator.free(host_name_buffer); + if (shutdown) { return std.process.execv(allocator, &[_][]const u8{ "/bin/sh", "-c", config.ly.shutdown_cmd }); } else if (restart) { diff --git a/src/tui/components/Desktop.zig b/src/tui/components/Desktop.zig index ac5604e..ba70f72 100644 --- a/src/tui/components/Desktop.zig +++ b/src/tui/components/Desktop.zig @@ -103,7 +103,7 @@ pub fn addEnvironmentWithBuffer(self: *Desktop, entry_buffer: []u8, name: []cons } pub fn crawl(self: *Desktop, path: []const u8, display_server: DisplayServer) !void { - var directory = try std.fs.openDirAbsolute(path, .{}); + var directory = std.fs.openDirAbsolute(path, .{}) catch return; defer directory.close(); var iterable_directory = try std.fs.openIterableDirAbsolute(path, .{});