summaryrefslogtreecommitdiff
path: root/src/FoldData.zig
diff options
context:
space:
mode:
authorGravatar Jose Colon Rodriguez2024-03-28 10:06:00 -0400
committerGravatar Jose Colon Rodriguez2024-03-28 10:06:00 -0400
commit74be85ac145cc6de5d03348e07be8d982c2211cb (patch)
treeb3b5f2080235e5cf73d2be080fb70583567dfb2b /src/FoldData.zig
parentScriptsData and made all Datas const (diff)
downloadzg-74be85ac145cc6de5d03348e07be8d982c2211cb.tar.gz
zg-74be85ac145cc6de5d03348e07be8d982c2211cb.tar.xz
zg-74be85ac145cc6de5d03348e07be8d982c2211cb.zip
PropsData and errdefers for init fns
Diffstat (limited to 'src/FoldData.zig')
-rw-r--r--src/FoldData.zig8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/FoldData.zig b/src/FoldData.zig
index e387447..a06eefe 100644
--- a/src/FoldData.zig
+++ b/src/FoldData.zig
@@ -24,6 +24,13 @@ pub fn init(allocator: mem.Allocator) !Self {
24 .cwcf = try allocator.alloc(bool, 0x110000), 24 .cwcf = try allocator.alloc(bool, 0x110000),
25 }; 25 };
26 26
27 var slices: usize = 0;
28 errdefer {
29 for (self.fold[0..slices]) |slice| self.allocator.free(slice);
30 self.allocator.free(self.fold);
31 self.allocator.free(self.cwcf);
32 }
33
27 @memset(self.fold, &.{}); 34 @memset(self.fold, &.{});
28 @memset(self.cwcf, false); 35 @memset(self.cwcf, false);
29 36
@@ -32,6 +39,7 @@ pub fn init(allocator: mem.Allocator) !Self {
32 if (len == 0) break; 39 if (len == 0) break;
33 const cp = try reader.readInt(u24, endian); 40 const cp = try reader.readInt(u24, endian);
34 self.fold[cp >> 1] = try allocator.alloc(u21, len - 1); 41 self.fold[cp >> 1] = try allocator.alloc(u21, len - 1);
42 slices += 1;
35 for (0..len - 1) |i| { 43 for (0..len - 1) |i| {
36 self.fold[cp >> 1][i] = @intCast(try reader.readInt(u24, endian)); 44 self.fold[cp >> 1][i] = @intCast(try reader.readInt(u24, endian));
37 } 45 }