aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-02-20 03:45:49 +0100
committerJunio C Hamano <junkio@cox.net>2007-02-19 19:02:12 -0800
commiteac70c4f64a618744e05d4a5be61a356c0011033 (patch)
treea7c4e9bf2ed14fda8804a6e22560a0f00bc6aaea
parent56185f49d03cae28048146e902089ea366c6cd6c (diff)
downloadgit-eac70c4f64a618744e05d4a5be61a356c0011033.tar.gz
git-eac70c4f64a618744e05d4a5be61a356c0011033.tar.xz
apply: fix memory leak in prefix_one()
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--builtin-apply.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/builtin-apply.c b/builtin-apply.c
index 053511e2e..2a40af3ff 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2502,11 +2502,13 @@ static int use_patch(struct patch *p)
return 1;
}
-static char *prefix_one(char *name)
+static void prefix_one(char **name)
{
- if (!name)
- return name;
- return xstrdup(prefix_filename(prefix, prefix_length, name));
+ char *old_name = *name;
+ if (!old_name)
+ return;
+ *name = xstrdup(prefix_filename(prefix, prefix_length, *name));
+ free(old_name);
}
static void prefix_patches(struct patch *p)
@@ -2514,8 +2516,9 @@ static void prefix_patches(struct patch *p)
if (!prefix)
return;
for ( ; p; p = p->next) {
- p->new_name = prefix_one(p->new_name);
- p->old_name = prefix_one(p->old_name);
+ if (p->new_name != p->old_name)
+ prefix_one(&p->new_name);
+ prefix_one(&p->old_name);
}
}