summaryrefslogtreecommitdiff
path: root/src/CanonData.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/CanonData.zig')
-rw-r--r--src/CanonData.zig10
1 files changed, 9 insertions, 1 deletions
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 {
24 .nfd = try allocator.alloc([]u21, 0x110000), 24 .nfd = try allocator.alloc([]u21, 0x110000),
25 }; 25 };
26 26
27 var slices: usize = 0;
28 errdefer {
29 self.nfc.deinit();
30 for (self.nfd[0..slices]) |slice| self.allocator.free(slice);
31 self.allocator.free(self.nfd);
32 }
33
27 @memset(self.nfd, &.{}); 34 @memset(self.nfd, &.{});
28 35
29 while (true) { 36 while (true) {
@@ -31,6 +38,7 @@ pub fn init(allocator: mem.Allocator) !Self {
31 if (len == 0) break; 38 if (len == 0) break;
32 const cp = try reader.readInt(u24, endian); 39 const cp = try reader.readInt(u24, endian);
33 self.nfd[cp] = try allocator.alloc(u21, len - 1); 40 self.nfd[cp] = try allocator.alloc(u21, len - 1);
41 slices += 1;
34 for (0..len - 1) |i| { 42 for (0..len - 1) |i| {
35 self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian)); 43 self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian));
36 } 44 }
@@ -42,7 +50,7 @@ pub fn init(allocator: mem.Allocator) !Self {
42 return self; 50 return self;
43} 51}
44 52
45pub fn deinit(self: *const Self) void { 53pub fn deinit(self: *Self) void {
46 self.nfc.deinit(); 54 self.nfc.deinit();
47 for (self.nfd) |slice| self.allocator.free(slice); 55 for (self.nfd) |slice| self.allocator.free(slice);
48 self.allocator.free(self.nfd); 56 self.allocator.free(self.nfd);