Audit usages of toOwnedSlice (#32001)

Followup to #30769

I grepped for `try .*toOwnedSlice` and checked all of them by hand.

Fixes a bunch of memory leaks removes usages or `errdefer` and `vars` in some places. I also switched array_list.Managed to ArrayList where it was convenient.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32001
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
This commit is contained in:
andrew.kraevskii
2026-04-22 19:35:46 +02:00
committed by Andrew Kelley
parent 03955476ad
commit bbab366b78
20 changed files with 198 additions and 182 deletions
+5 -9
View File
@@ -311,17 +311,13 @@ pub fn endInput(p: *Parser) Allocator.Error!Document {
p.scratch_string.items.len = 0;
p.scratch_extra.items.len = 0;
var nodes = p.nodes.toOwnedSlice();
errdefer nodes.deinit(p.allocator);
const extra = try p.extra.toOwnedSlice(p.allocator);
errdefer p.allocator.free(extra);
const string_bytes = try p.string_bytes.toOwnedSlice(p.allocator);
errdefer p.allocator.free(string_bytes);
try p.extra.shrinkToLen(p.allocator);
try p.string_bytes.shrinkToLen(p.allocator);
return .{
.nodes = nodes,
.extra = extra,
.string_bytes = string_bytes,
.nodes = p.nodes.toOwnedSlice(),
.extra = p.extra.toOwnedSliceAssert(),
.string_bytes = p.string_bytes.toOwnedSliceAssert(),
};
}