diff options
| author | Lidong Yan <502024330056@smail.nju.edu.cn> | 2025-05-14 13:53:28 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-05-15 13:53:33 -0700 |
| commit | 044511f889b1989840339a322f84e50dfa3bf6e0 (patch) | |
| tree | 34d2338fa838dceda15b0ea5047fd97cb93df541 | |
| parent | 1a8a4971cc6c179c4dd711f4a7f5d7178f4b3ab7 (diff) | |
| download | git-044511f889b1989840339a322f84e50dfa3bf6e0.tar.xz | |
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 <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
| -rw-r--r-- | sequencer.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sequencer.c b/sequencer.c index b5c4043757..5fb7b68a7a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -6596,6 +6596,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) char **subjects; struct commit_todo_item commit_todo; struct todo_item *items = NULL; + int ret = 0; init_commit_todo_item(&commit_todo); /* @@ -6626,8 +6627,8 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) } if (is_fixup(item->command)) { - clear_commit_todo_item(&commit_todo); - return error(_("the script was already rearranged.")); + ret = error(_("the script was already rearranged.")); + goto cleanup; } repo_parse_commit(the_repository, item->commit); @@ -6729,6 +6730,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) todo_list->items = items; } +cleanup: free(next); free(tail); for (i = 0; i < todo_list->nr; i++) @@ -6738,7 +6740,7 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) clear_commit_todo_item(&commit_todo); - return 0; + return ret; } int sequencer_determine_whence(struct repository *r, enum commit_whence *whence) |
