git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] apply: fix memory leak in prefix_one()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 20, 2007, 02:45 UTC
Message-ID
<Pine.LNX.4.63.0702200345070.22628@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vbqjp3630.fsf@assigned-by-dhcp.cox.net>
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 19 of 49 in “Teach core.autocrlf to 'git apply'”
  1. Teach core.autocrlf to 'git apply'Junio C Hamano, Feb 17, 2007
  2. Teach 'git apply' to look at $GIT_DIR/configJunio C Hamano, Feb 17, 2007
  3. Jeff KingFeb 17, 2007
  4. Junio C HamanoFeb 17, 2007
  5. Jeff KingFeb 17, 2007
  6. Linus TorvaldsFeb 19, 2007
  7. Shawn O. PearceFeb 19, 2007
  8. Junio C HamanoFeb 19, 2007
  9. Linus TorvaldsFeb 19, 2007
  10. Junio C HamanoFeb 19, 2007
  11. Linus TorvaldsFeb 20, 2007
  12. Junio C HamanoFeb 20, 2007
  13. Johannes SchindelinFeb 20, 2007
  14. Junio C HamanoFeb 20, 2007
  15. Johannes SchindelinFeb 20, 2007
  16. git-apply: require -p<n> when working in a subdirectory.Junio C Hamano, Feb 20, 2007
  17. apply: fix memory leak in prefix_one()Johannes Schindelin, Feb 20, 2007
  18. Junio C HamanoFeb 20, 2007
  19. Johannes SchindelinFeb 20, 2007
  20. git-apply: do not lose cwd when run from a subdirectory.Junio C Hamano, Feb 20, 2007
  21. Junio C HamanoFeb 20, 2007
  22. Linus TorvaldsFeb 20, 2007
  23. Daniel BarkalowFeb 21, 2007
  24. Junio C HamanoFeb 21, 2007
  25. Daniel BarkalowFeb 21, 2007
  26. Linus TorvaldsFeb 21, 2007
  27. Junio C HamanoFeb 21, 2007
  28. git-apply: notice "diff --git" patch againJunio C Hamano, Feb 21, 2007
  29. git-apply: guess correct -p<n> value for non-git patches.Junio C Hamano, Feb 22, 2007
  30. Johannes SchindelinFeb 20, 2007
  31. Simon 'corecode' SchubertFeb 20, 2007
  32. Johannes SchindelinFeb 18, 2007
  33. Junio C HamanoFeb 18, 2007
  34. Johannes SchindelinFeb 18, 2007
  35. Junio C HamanoFeb 18, 2007
  36. Johannes SchindelinFeb 18, 2007
  37. Junio C HamanoFeb 18, 2007
  38. Johannes SchindelinFeb 18, 2007
  39. Junio C HamanoFeb 18, 2007
  40. Johannes SchindelinFeb 18, 2007
  41. Jakub NarebskiFeb 18, 2007
  42. Johannes SchindelinFeb 18, 2007
  43. Junio C HamanoFeb 18, 2007
  44. Johannes SchindelinFeb 18, 2007
  45. Junio C HamanoFeb 18, 2007
  46. Johannes SchindelinFeb 18, 2007
  47. Junio C HamanoFeb 18, 2007
  48. Johannes SchindelinFeb 18, 2007
  49. Junio C HamanoFeb 18, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.