Skip to content

Commit f09935f

Browse files
mstdokumacijinzhongjia
authored andcommitted
chore: apply code review changes
1 parent 67e2b37 commit f09935f

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/msgpack.zig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,9 @@ fn clonePayload(payload: Payload, allocator: Allocator) !Payload {
869869
var success = false;
870870
defer if (!success) {
871871
// cleanup partial clones on error
872-
for (0..cloned_count) |j| {
872+
var j: usize = cloned_count;
873+
while (j > 0) {
874+
j -= 1;
873875
new_arr[j].free(allocator);
874876
}
875877
allocator.free(new_arr);
@@ -889,13 +891,7 @@ fn clonePayload(payload: Payload, allocator: Allocator) !Payload {
889891
var new_map = Map.init(allocator);
890892
var success = false;
891893
defer if (!success) {
892-
// Free any partially-inserted keys/values on error before deinit
893-
var it2 = new_map.map.iterator();
894-
while (it2.next()) |entry| {
895-
entry.key_ptr.*.free(allocator);
896-
entry.value_ptr.*.free(allocator);
897-
}
898-
new_map.deinit();
894+
(Payload{ .map = new_map }).free(allocator);
899895
};
900896

901897
// Clone all entries

0 commit comments

Comments
 (0)