From f188afc25c6da0fd3422c9c2e404ea35a2c07771 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 27 Oct 2025 14:05:54 -0700 Subject: [PATCH] fix memory leak when a non-existant exec process is specified --- src/main.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index aaf4e8f..d06c524 100644 --- a/src/main.zig +++ b/src/main.zig @@ -67,9 +67,13 @@ const SpeechHandler = struct { // SAFETY: this is set 8 lines below before use .id = undefined, }; + errdefer self.allocator.destroy(process.child.?); process.child.?.* = std.process.Child.init(&[_][]const u8{ program, text }, self.allocator); try self.child_processes.append(self.allocator, process); - errdefer _ = self.child_processes.pop(); + errdefer { + _ = self.child_processes.pop(); + self.child_processes.shrinkAndFree(self.allocator, self.child_processes.items.len); + } try process.child.?.spawn(); try process.child.?.waitForSpawn(); process.id = process.child.?.id;