Skip to content

Commit 525466b

Browse files
std.zig.Ast: Fix error case memory leak in parse()
1 parent 89db4f2 commit 525466b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/std/zig/Ast.zig

+7-2
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,19 @@ pub fn parse(gpa: Allocator, source: [:0]const u8, mode: Mode) Allocator.Error!A
181181
.zon => try parser.parseZon(),
182182
}
183183

184+
const extra_data = try parser.extra_data.toOwnedSlice(gpa);
185+
errdefer gpa.free(extra_data);
186+
const errors = try parser.errors.toOwnedSlice(gpa);
187+
errdefer gpa.free(errors);
188+
184189
// TODO experiment with compacting the MultiArrayList slices here
185190
return Ast{
186191
.source = source,
187192
.mode = mode,
188193
.tokens = tokens.toOwnedSlice(),
189194
.nodes = parser.nodes.toOwnedSlice(),
190-
.extra_data = try parser.extra_data.toOwnedSlice(gpa),
191-
.errors = try parser.errors.toOwnedSlice(gpa),
195+
.extra_data = extra_data,
196+
.errors = errors,
192197
};
193198
}
194199

0 commit comments

Comments
 (0)