mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
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:
committed by
Andrew Kelley
parent
03955476ad
commit
bbab366b78
@@ -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(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user