fix: don't leak Buffer.file_path

This commit is contained in:
CJ van den Berg 2025-08-05 15:24:18 +02:00
parent 886a2582a3
commit c88e2dd975
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
5 changed files with 28 additions and 16 deletions

View file

@ -1316,11 +1316,11 @@ fn get_next_mru_buffer(self: *Self) ?[]const u8 {
defer self.allocator.free(buffers);
const active_file_path = self.get_active_file_path();
for (buffers) |buffer| {
if (active_file_path) |fp| if (std.mem.eql(u8, fp, buffer.file_path))
if (active_file_path) |fp| if (std.mem.eql(u8, fp, buffer.get_file_path()))
continue;
if (buffer.hidden)
continue;
return buffer.file_path;
return buffer.get_file_path();
}
return null;
}

View file

@ -34,7 +34,7 @@ pub fn load_entries(palette: *Type) !usize {
else
"";
(try palette.entries.addOne()).* = .{
.label = buffer.file_path,
.label = buffer.get_file_path(),
.icon = buffer.file_type_icon orelse "",
.color = buffer.file_type_color,
.indicator = indicator,

View file

@ -265,7 +265,7 @@ const TabBar = struct {
fn navigate_to_tab(tab: *const TabBarTab) void {
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
if (buffer_manager.buffer_from_ref(tab.buffer_ref)) |buffer|
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.file_path } }) catch {};
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.get_file_path() } }) catch {};
}
};
@ -298,13 +298,13 @@ const Tab = struct {
fn on_click(self: *@This(), _: *Button.State(@This())) void {
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
if (buffer_manager.buffer_from_ref(self.buffer_ref)) |buffer|
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.file_path } }) catch {};
tp.self_pid().send(.{ "cmd", "navigate", .{ .file = buffer.get_file_path() } }) catch {};
}
fn on_click2(self: *@This(), _: *Button.State(@This())) void {
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
if (buffer_manager.buffer_from_ref(self.buffer_ref)) |buffer|
tp.self_pid().send(.{ "cmd", "close_buffer", .{buffer.file_path} }) catch {};
tp.self_pid().send(.{ "cmd", "close_buffer", .{buffer.get_file_path()} }) catch {};
}
fn render(self: *@This(), btn: *Button.State(@This()), theme: *const Widget.Theme) bool {
@ -450,7 +450,7 @@ const Tab = struct {
}
fn name_from_buffer(buffer: *Buffer) []const u8 {
const file_path = buffer.file_path;
const file_path = buffer.get_file_path();
if (file_path.len > 0 and file_path[0] == '*')
return file_path;
const basename_begin = std.mem.lastIndexOfScalar(u8, file_path, std.fs.path.sep);