Skip to content

Commit b81d905

Browse files
committed
errdefer alloc
1 parent fa6f304 commit b81d905

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/msgpack.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ pub fn Pack(
11361136
/// read data
11371137
pub fn read_data(self: Self, allocator: Allocator, len: usize) ![]u8 {
11381138
const data = try allocator.alloc(u8, len);
1139+
errdefer allocator.free(data);
11391140
const data_len = try self.read_fn(data);
11401141

11411142
if (data_len != len) {
@@ -1756,6 +1757,7 @@ pub fn Pack(
17561757
}
17571758

17581759
const arr = try allocator.alloc(T, len);
1760+
errdefer allocator.free(arr);
17591761
for (0..arr.len) |i| {
17601762
arr[i] = try self.read(T, allocator);
17611763
}

0 commit comments

Comments
 (0)