From e04cc8cc66d0bd44eb4b7dadc1c46cf77d5ced94 Mon Sep 17 00:00:00 2001 From: ktkk Date: Tue, 23 Jun 2026 20:53:14 +0200 Subject: [PATCH] Fix memory leaks --- src/Class.zig | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Class.zig b/src/Class.zig index d5fb701..3d8175a 100644 --- a/src/Class.zig +++ b/src/Class.zig @@ -1378,9 +1378,9 @@ pub const AttributeInfo = struct { pub fn deinit(self: *ElementValue, allocator: std.mem.Allocator) void { switch (self.*) { - .annotation_value => |element_value| element_value.deinit(allocator), + .annotation_value => |*element_value| element_value.deinit(allocator), .array_value => |element_value| { - for (element_value.values) |value| { + for (element_value.values) |*value| { value.deinit(allocator); } allocator.free(element_value.values); @@ -1481,16 +1481,32 @@ pub const AttributeInfo = struct { .line_number_table => |attribute| allocator.free(attribute.line_number_table), .local_variable_table => |attribute| allocator.free(attribute.local_variable_table), .local_variable_type_table => |attribute| allocator.free(attribute.local_variable_type_table), - .runtime_visible_annotations => |attribute| allocator.free(attribute.annotations), - .runtime_invisible_annotations => |attribute| allocator.free(attribute.annotations), + .runtime_visible_annotations => |attribute| { + for (attribute.annotations) |*annotation| { + annotation.deinit(allocator); + } + allocator.free(attribute.annotations); + }, + .runtime_invisible_annotations => |attribute| { + for (attribute.annotations) |*annotation| { + annotation.deinit(allocator); + } + allocator.free(attribute.annotations); + }, .runtime_visible_parameter_annotations => |attribute| { for (attribute.parameter_annotations) |parameter_annotation| { + for (parameter_annotation.annotations) |*annotation| { + annotation.deinit(allocator); + } allocator.free(parameter_annotation.annotations); } allocator.free(attribute.parameter_annotations); }, .runtime_invisible_parameter_annotations => |attribute| { for (attribute.parameter_annotations) |parameter_annotation| { + for (parameter_annotation.annotations) |*annotation| { + annotation.deinit(allocator); + } allocator.free(parameter_annotation.annotations); } allocator.free(attribute.parameter_annotations);