From 35930b160081d98b9f959c15ef20b707aad6b28e Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreplay.github.com> Date: Thu, 21 Jul 2022 14:10:09 +1000 Subject: [PATCH] examples/gkurve: ResizableLabel: fix deinit leaks This issue with the previous (commented out) implementation was that by remaking the iterator each loop, the same element was attempted to be freed each iteration, as the element was not actually removed from the map. --- examples/gkurve/resizable_label.zig | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/gkurve/resizable_label.zig b/examples/gkurve/resizable_label.zig index cc9502d4..30d4a588 100644 --- a/examples/gkurve/resizable_label.zig +++ b/examples/gkurve/resizable_label.zig @@ -31,6 +31,14 @@ const CharVertices = struct { // But the other two points do, so put those in the indices convex_vertices: VertexList, convex_vertices_indices: std.ArrayList(u16), + + fn deinit(self: CharVertices) void { + self.filled_vertices.deinit(); + self.filled_vertices_indices.deinit(); + self.concave_vertices.deinit(); + self.convex_vertices.deinit(); + self.convex_vertices_indices.deinit(); + } }; face: ft.Face, @@ -77,16 +85,12 @@ pub fn init(self: *ResizableLabel, lib: ft.Library, font_path: []const u8, face_ pub fn deinit(label: *ResizableLabel) void { label.face.deinit(); label.tessellator.deinit(); - // FIXME: - // std.debug.todo("valueIterator() doesn't stop? How do we deallocate the values?"); - // while (label.char_map.valueIterator().next()) |value| { - // _ = value; - // value.filled_vertices.deinit(); - // value.filled_vertices_indices.deinit(); - // value.convex_vertices.deinit(); - // value.convex_vertices_indices.deinit(); - // value.concave_vertices.deinit(); - // } + + var iter = label.char_map.valueIterator(); + while (iter.next()) |ptr| { + ptr.deinit(); + } + label.char_map.deinit(); }