Ensure memory is freed when error code is returned

main
Hammy 3 years ago
parent 8bddbe6a7c
commit ac9e36bdef

@ -103,15 +103,20 @@ int List_merge(List *list, int start_index, int mid_index, int end_index) {
} }
List *right = List_slice(list, mid_index + 1, end_index + 1); List *right = List_slice(list, mid_index + 1, end_index + 1);
if (!right) { if (!right) {
List_destroy(&left);
return 1; return 1;
} }
int leftSuccessCode = List_append(left, INT_MAX); int leftSuccessCode = List_append(left, INT_MAX);
if (leftSuccessCode != 0) { if (leftSuccessCode != 0) {
List_destroy(&left);
List_destroy(&right);
return 1; return 1;
} }
int rightSuccessCode = List_append(right, INT_MAX); int rightSuccessCode = List_append(right, INT_MAX);
if (rightSuccessCode != 0) { if (rightSuccessCode != 0) {
List_destroy(&left);
List_destroy(&right);
return 1; return 1;
} }

Loading…
Cancel
Save