Skip to content

Commit ab9d75a

Browse files
committed
revision: note the lack of free() in simplify_merges()
Among the three similar-looking loops that walk singly linked commit_list, the first one is only peeking and the same list is later used for real work. Leave a comment not to mistakenly free its elements there. Signed-off-by: Junio C Hamano <[email protected]>
1 parent a52f007 commit ab9d75a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

revision.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,23 +2015,31 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
20152015

20162016
static void simplify_merges(struct rev_info *revs)
20172017
{
2018-
struct commit_list *list;
2018+
struct commit_list *list, *next;
20192019
struct commit_list *yet_to_do, **tail;
2020+
struct commit *commit;
20202021

20212022
if (!revs->prune)
20222023
return;
20232024

20242025
/* feed the list reversed */
20252026
yet_to_do = NULL;
2026-
for (list = revs->commits; list; list = list->next)
2027-
commit_list_insert(list->item, &yet_to_do);
2027+
for (list = revs->commits; list; list = next) {
2028+
commit = list->item;
2029+
next = list->next;
2030+
/*
2031+
* Do not free(list) here yet; the original list
2032+
* is used later in this function.
2033+
*/
2034+
commit_list_insert(commit, &yet_to_do);
2035+
}
20282036
while (yet_to_do) {
20292037
list = yet_to_do;
20302038
yet_to_do = NULL;
20312039
tail = &yet_to_do;
20322040
while (list) {
2033-
struct commit *commit = list->item;
2034-
struct commit_list *next = list->next;
2041+
commit = list->item;
2042+
next = list->next;
20352043
free(list);
20362044
list = next;
20372045
tail = simplify_one(revs, commit, tail);
@@ -2043,9 +2051,10 @@ static void simplify_merges(struct rev_info *revs)
20432051
revs->commits = NULL;
20442052
tail = &revs->commits;
20452053
while (list) {
2046-
struct commit *commit = list->item;
2047-
struct commit_list *next = list->next;
20482054
struct merge_simplify_state *st;
2055+
2056+
commit = list->item;
2057+
next = list->next;
20492058
free(list);
20502059
list = next;
20512060
st = locate_simplify_state(revs, commit);

0 commit comments

Comments
 (0)