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 <gitster@pobox.com>

Junio C Hamano committed Jun 8, 2012 at 14:50 UTC ab9d75a8d7e48e03ab0be9fc5e38902f1c173b87
1 file changed +16 -7
revision.c
+16 -7
@@ -2015,23 +2015,31 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
2015
2016 static void simplify_merges(struct rev_info *revs)
2017 {
2018 - struct commit_list *list;
2018 + struct commit_list *list, *next;
2019 struct commit_list *yet_to_do, **tail;
2020 + struct commit *commit;
2021
2022 if (!revs->prune)
2023 return;
2024
2025 /* feed the list reversed */
2026 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 + }
2036 while (yet_to_do) {
2037 list = yet_to_do;
2038 yet_to_do = NULL;
2039 tail = &yet_to_do;
2040 while (list) {
2033 - struct commit *commit = list->item;
2034 - struct commit_list *next = list->next;
2041 + commit = list->item;
2042 + next = list->next;
2043 free(list);
2044 list = next;
2045 tail = simplify_one(revs, commit, tail);
@@ -2043,9 +2051,10 @@ static void simplify_merges(struct rev_info *revs)
2051 revs->commits = NULL;
2052 tail = &revs->commits;
2053 while (list) {
2046 - struct commit *commit = list->item;
2047 - struct commit_list *next = list->next;
2054 struct merge_simplify_state *st;
2055 +
2056 + commit = list->item;
2057 + next = list->next;
2058 free(list);
2059 list = next;
2060 st = locate_simplify_state(revs, commit);