@@ -101,18 +101,22 @@ static struct rev_name *create_or_update_name(struct commit *commit,
}
static void name_rev(struct commit *start_commit,
- const char *tip_name, timestamp_t taggerdate,
+ const char *start_tip_name, timestamp_t taggerdate,
int from_tag, int deref)
{
struct commit_list *list = NULL;
+ const char *tip_name;
char *to_free = NULL;
parse_commit(start_commit);
if (start_commit->date < cutoff)
return;
- if (deref)
- tip_name = to_free = xstrfmt("%s^0", tip_name);
+ if (deref) {
+ tip_name = to_free = xstrfmt("%s^0", start_tip_name);
+ free((char*) start_tip_name);
+ } else
+ tip_name = start_tip_name;
if (!create_or_update_name(start_commit, tip_name, taggerdate, 0, 0,
from_tag)) {
The name_rev() function's 'tip_name' parameter is a freshly xstrdup()ed string, so when name_rev() invokes: tip_name = xstrfmt("%s^0", tip_name); then the original 'tip_name' string is leaked. Make sure that this string is free()d after it has been used as input for that xstrfmt() call. This only happens when name_rev() is invoked with a tag, i.e. relatively infrequently in a usual repository, so any reduction in memory usage is lost in the noise. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> --- builtin/name-rev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)