From 74be85ac145cc6de5d03348e07be8d982c2211cb Mon Sep 17 00:00:00 2001 From: Jose Colon Rodriguez Date: Thu, 28 Mar 2024 10:06:00 -0400 Subject: PropsData and errdefers for init fns --- src/CanonData.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/CanonData.zig') diff --git a/src/CanonData.zig b/src/CanonData.zig index 9f1deb8..64d5555 100644 --- a/src/CanonData.zig +++ b/src/CanonData.zig @@ -24,6 +24,13 @@ pub fn init(allocator: mem.Allocator) !Self { .nfd = try allocator.alloc([]u21, 0x110000), }; + var slices: usize = 0; + errdefer { + self.nfc.deinit(); + for (self.nfd[0..slices]) |slice| self.allocator.free(slice); + self.allocator.free(self.nfd); + } + @memset(self.nfd, &.{}); while (true) { @@ -31,6 +38,7 @@ pub fn init(allocator: mem.Allocator) !Self { if (len == 0) break; const cp = try reader.readInt(u24, endian); self.nfd[cp] = try allocator.alloc(u21, len - 1); + slices += 1; for (0..len - 1) |i| { self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian)); } @@ -42,7 +50,7 @@ pub fn init(allocator: mem.Allocator) !Self { return self; } -pub fn deinit(self: *const Self) void { +pub fn deinit(self: *Self) void { self.nfc.deinit(); for (self.nfd) |slice| self.allocator.free(slice); self.allocator.free(self.nfd); -- cgit v1.2.3