commit 11c3b4bd4178c78af103f5397fc3aafd09a2a979 (tree)
parent 0f51f663f06728f38f518073a23d69a7c1b0d792
Author: llogick <16590917+llogick@users.noreply.github.com>
Date: Tue, 27 Jan 2026 14:58:24 -0800
Fix std.process.run leaking memory if child.wait returned an error
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/std/process.zig b/lib/std/process.zig
@@ -533,10 +533,16 @@ pub fn run(gpa: Allocator, io: Io, options: RunOptions) RunError!RunResult {
try child.collectOutput(gpa, &stdout, &stderr, options.max_output_bytes);
+ const term = try child.wait(io);
+
+ const owned_stdout = try stdout.toOwnedSlice(gpa);
+ errdefer gpa.free(owned_stdout);
+ const owned_stderr = try stderr.toOwnedSlice(gpa);
+
return .{
- .stdout = try stdout.toOwnedSlice(gpa),
- .stderr = try stderr.toOwnedSlice(gpa),
- .term = try child.wait(io),
+ .stdout = owned_stdout,
+ .stderr = owned_stderr,
+ .term = term,
};
}