Skip to content

Commit 044511f

Browse files
brandb97gitster
authored andcommitted
sequencer: fix memory leak if todo_list_rearrange_squash() failed
In sequencer.c:todo_list_rearrange_squash, if it fails, memory allocated in `next`, `tail`, `subjects` and `subject2item` will leak. Jump to cleanup label before return could fix this leak problem. Signed-off-by: Lidong Yan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a8a497 commit 044511f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sequencer.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6596,6 +6596,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
65966596
char **subjects;
65976597
struct commit_todo_item commit_todo;
65986598
struct todo_item *items = NULL;
6599+
int ret = 0;
65996600

66006601
init_commit_todo_item(&commit_todo);
66016602
/*
@@ -6626,8 +6627,8 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
66266627
}
66276628

66286629
if (is_fixup(item->command)) {
6629-
clear_commit_todo_item(&commit_todo);
6630-
return error(_("the script was already rearranged."));
6630+
ret = error(_("the script was already rearranged."));
6631+
goto cleanup;
66316632
}
66326633

66336634
repo_parse_commit(the_repository, item->commit);
@@ -6729,6 +6730,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
67296730
todo_list->items = items;
67306731
}
67316732

6733+
cleanup:
67326734
free(next);
67336735
free(tail);
67346736
for (i = 0; i < todo_list->nr; i++)
@@ -6738,7 +6740,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
67386740

67396741
clear_commit_todo_item(&commit_todo);
67406742

6741-
return 0;
6743+
return ret;
67426744
}
67436745

67446746
int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)

0 commit comments

Comments
 (0)