On 9/19/2019 5:47 PM, SZEDER Gábor wrote: > At the beginning of the recursive name_rev() function it creates a new > 'struct rev_name' instance for each previously unvisited commit or, if > this visit results in better name for an already visited commit, then > updates the 'struct rev_name' instance attached to to the commit, or > returns early. > > Restructure this so it's caller creates or updates the 'struct > rev_name' instance associated with the commit to be passed as > parameter, i.e. both name_ref() before calling name_rev() and > name_rev() itself as it iterates over the parent commits. > > This makes eliminating the recursion a bit easier to follow, and it > will be moved back to name_rev() after the recursion is eliminated. > > This change also plugs the memory leak that was temporarily unplugged > in the earlier "name-rev: pull out deref handling from the recursion" > patch in this series. [snip] > > @@ -276,11 +277,17 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo > path = name_ref_abbrev(path, can_abbreviate_output); > if (commit->date >= cutoff) { > const char *tip_name; > + char *to_free = NULL; > if (deref) > - tip_name = xstrfmt("%s^0", path); > + tip_name = to_free = xstrfmt("%s^0", path); > else > tip_name = xstrdup(path); So this xstrdup(path) is not a leak? > - name_rev(commit, tip_name, taggerdate, 0, 0, from_tag); > + if (create_or_update_name(commit, tip_name, taggerdate, > + 0, 0, from_tag)) > + name_rev(commit, tip_name, taggerdate, 0, 0, > + from_tag); > + else > + free(to_free); > } > } > return 0; >