fix: avoid some potential memory leaks in ripgrep and filelist_view

This commit is contained in:
CJ van den Berg 2024-11-04 22:17:39 +01:00
parent cfb9f8cf11
commit 9421f4e7f6
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 6 additions and 0 deletions

View file

@ -100,10 +100,14 @@ const Process = struct {
} }
fn deinit(self: *Process) void { fn deinit(self: *Process) void {
if (self.sp) |*sp| sp.deinit();
self.parent.deinit();
self.output.deinit(); self.output.deinit();
self.logger.deinit(); self.logger.deinit();
self.allocator.free(self.tag);
self.allocator.free(self.query); self.allocator.free(self.query);
self.close() catch {}; self.close() catch {};
self.allocator.destroy(self);
} }
fn close(self: *Process) tp.result { fn close(self: *Process) tp.result {
@ -114,6 +118,7 @@ const Process = struct {
} }
fn start(self: *Process) tp.result { fn start(self: *Process) tp.result {
errdefer self.deinit();
_ = tp.set_trap(true); _ = tp.set_trap(true);
const args = tp.message.fmt(.{ const args = tp.message.fmt(.{
ripgrep_binary, ripgrep_binary,

View file

@ -67,6 +67,7 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget {
} }
pub fn deinit(self: *Self, allocator: Allocator) void { pub fn deinit(self: *Self, allocator: Allocator) void {
self.reset();
self.plane.deinit(); self.plane.deinit();
self.commands.deinit(); self.commands.deinit();
allocator.destroy(self); allocator.destroy(self);