File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -866,33 +866,28 @@ fn clonePayload(payload: Payload, allocator: Allocator) !Payload {
866866 .arr = > | arr | {
867867 const new_arr = try allocator .alloc (Payload , arr .len );
868868 var cloned_count : usize = 0 ;
869- var success = false ;
870- defer if (! success ) {
869+ errdefer {
871870 // cleanup partial clones on error
872871 var j : usize = cloned_count ;
873872 while (j > 0 ) {
874873 j -= 1 ;
875874 new_arr [j ].free (allocator );
876875 }
877876 allocator .free (new_arr );
878- };
877+ }
879878
880879 for (arr , 0.. ) | item , i | {
881880 const cloned_item = try clonePayload (item , allocator );
882881 new_arr [i ] = cloned_item ;
883882 cloned_count += 1 ;
884883 }
885884
886- success = true ;
887885 return Payload { .arr = new_arr };
888886 },
889887
890888 .map = > | m | {
891889 var new_map = Map .init (allocator );
892- var success = false ;
893- defer if (! success ) {
894- (Payload { .map = new_map }).free (allocator );
895- };
890+ errdefer new_map .deinit ();
896891
897892 // Clone all entries
898893 var it = m .map .iterator ();
@@ -906,7 +901,6 @@ fn clonePayload(payload: Payload, allocator: Allocator) !Payload {
906901 try new_map .putInternal (cloned_key , cloned_value );
907902 }
908903
909- success = true ;
910904 return Payload { .map = new_map };
911905 },
912906 };
You can’t perform that action at this time.
0 commit comments