mirror of
https://github.com/git/git.git
synced 2024-10-29 21:37:53 +01:00
name-rev: avoid leaking memory in the deref
case
When the `name_rev()` function is asked to dereference the tip name, it allocates memory. But when it turns out that another tip already described the commit better than the current one, we forgot to release the memory. Pointed out by Coverity. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
3dc7ea91da
commit
5308224633
1 changed files with 5 additions and 2 deletions
|
@ -28,6 +28,7 @@ static void name_rev(struct commit *commit,
|
|||
struct rev_name *name = (struct rev_name *)commit->util;
|
||||
struct commit_list *parents;
|
||||
int parent_number = 1;
|
||||
char *to_free = NULL;
|
||||
|
||||
parse_commit(commit);
|
||||
|
||||
|
@ -35,7 +36,7 @@ static void name_rev(struct commit *commit,
|
|||
return;
|
||||
|
||||
if (deref) {
|
||||
tip_name = xstrfmt("%s^0", tip_name);
|
||||
tip_name = to_free = xstrfmt("%s^0", tip_name);
|
||||
|
||||
if (generation)
|
||||
die("generation: %d, but deref?", generation);
|
||||
|
@ -53,8 +54,10 @@ static void name_rev(struct commit *commit,
|
|||
name->taggerdate = taggerdate;
|
||||
name->generation = generation;
|
||||
name->distance = distance;
|
||||
} else
|
||||
} else {
|
||||
free(to_free);
|
||||
return;
|
||||
}
|
||||
|
||||
for (parents = commit->parents;
|
||||
parents;
|
||||
|
|
Loading…
Reference in a new issue