summaryrefslogtreecommitdiff
path: root/builtin/name-rev.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-05-04 13:59:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-08 03:18:20 (GMT)
commit5308224633cf138f436357b2a8a87a546373af72 (patch)
tree38df10b117d95a5a1f88df10fd8128d8da67450e /builtin/name-rev.c
parent3dc7ea91dab9959b6bec82c05df18d6d1bb70619 (diff)
downloadgit-5308224633cf138f436357b2a8a87a546373af72.zip
git-5308224633cf138f436357b2a8a87a546373af72.tar.gz
git-5308224633cf138f436357b2a8a87a546373af72.tar.bz2
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>
Diffstat (limited to 'builtin/name-rev.c')
-rw-r--r--builtin/name-rev.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 92a5d8a..e7a3fe7 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -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 @@ copy_data:
name->taggerdate = taggerdate;
name->generation = generation;
name->distance = distance;
- } else
+ } else {
+ free(to_free);
return;
+ }
for (parents = commit->parents;
parents;