describe: make own copy of refname
Do not retain a reference to the refname passed to the each_ref_fn callback get_name(), because there is no guarantee of the lifetimes of these names. Instead, make a local copy when needed. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
May 25, 2013 at 11:08 UTC
219a0f33cae0f164f4353b2171ecd4c08d5b7ced
1 file changed
+4
-2
builtin/describe.c
+4
-2
@@ -42,7 +42,7 @@ struct commit_name {
42
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
43
unsigned name_checked:1;
44
unsigned char sha1[20];
45
- const char *path;
45
+ char *path;
46
};
47
static const char *prio_names[] = {
48
"head", "lightweight", "annotated",
@@ -126,12 +126,14 @@ static void add_to_known_names(const char *path,
126
} else {
127
e->next = NULL;
128
}
129
+ e->path = NULL;
130
}
131
e->tag = tag;
132
e->prio = prio;
133
e->name_checked = 0;
134
hashcpy(e->sha1, sha1);
134
- e->path = path;
135
+ free(e->path);
136
+ e->path = xstrdup(path);
137
}
138
}
139