Re: [PATCH] apply: fix memory leak in prefix_one()
Hi,
On Mon, 19 Feb 2007, Junio C Hamano wrote:
Show 6 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > This is on top of them.
>
> I am not sure if this is correct. Don't we do some point
> new_name = old_name = blah?
Yes, you're right. I missed that. The change is in the last hunk:
--
[PATCH] apply: fix memory leak in prefix_one()
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
builtin-apply.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index e01969f..2a23138 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2516,11 +2516,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)
@@ -2528,8 +2530,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);
}
}
--
1.5.0.1.2141.gc066