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

[PATCH 3/2] Fix small memory leaks induced by diff_tree_setup_paths

From
Mike Hommey <mh@glandium.org>
Date
Dec 11, 2007, 21:59 UTC
Message-ID
<1197410395-30045-1-git-send-email-mh@glandium.org>
In-Reply-To
<1197407997-22945-2-git-send-email-mh@glandium.org>

Run diff_tree_release_paths in the appropriate places, and add a test to avoid NULL dereference. Better safe than sorry.

Signed-off-by: Mike Hommey <mh@glandium.org>
---
 There are a few more occurrences of diff_tree_setup_paths for which I don't
 know the code enough to correctly place the corresponding
 diff_tree_release_paths. Interesting the function existed but was never
 actually used ;)
 builtin-blame.c |    4 +++-
 builtin-reset.c |    1 +
 tree-diff.c     |    4 +++-
 3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index 523e55a..041901b 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -388,6 +388,7 @@ static struct origin *find_origin(struct scoreboard *sb,
 		}
 	}
 	diff_flush(&diff_opts);
+	diff_tree_release_paths(&diff_opts);
 	if (porigin) {
 		/*
 		 * Create a freestanding copy that is not part of
@@ -444,6 +445,7 @@ static struct origin *find_rename(struct scoreboard *sb,
 		}
 	}
 	diff_flush(&diff_opts);
+	diff_tree_release_paths(&diff_opts);
 	return porigin;
 }
 
@@ -1167,7 +1169,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
 		}
 	}
 	diff_flush(&diff_opts);
-
+	diff_tree_release_paths(&diff_opts);
 	return retval;
 }
 
diff --git a/builtin-reset.c b/builtin-reset.c
index 4c61025..713c2d5 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -158,6 +158,7 @@ static int read_from_tree(const char *prefix, const char **argv,
 		return 1;
 	diffcore_std(&opt);
 	diff_flush(&opt);
+	diff_tree_release_paths(&opt);
 
 	if (!index_was_discarded)
 		/* The index is still clobbered from do_diff_cache() */
diff --git a/tree-diff.c b/tree-diff.c
index aa0a100..a2fdf86 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -326,6 +326,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
 		die("unable to set up diff options to follow renames");
 	diff_tree(t1, t2, base, &diff_opts);
 	diffcore_std(&diff_opts);
+	diff_tree_release_paths(&diff_opts);
 
 	/* Go through the new set of filepairing, and see if we find a more interesting one */
 	for (i = 0; i < q->nr; i++) {
@@ -418,7 +419,8 @@ static int count_paths(const char **paths)
 
 void diff_tree_release_paths(struct diff_options *opt)
 {
-	free(opt->pathlens);
+	if (opt->pathlens)
+		free(opt->pathlens);
 }
 
 void diff_tree_setup_paths(const char **p, struct diff_options *opt)
-- 
1.5.3.7
Previous: Mike HommeyNext: Mike Hommey
Message 3 of 6 in “Fix XML parser leaks in http-push”
  1. 1/2 Fix XML parser leaks in http-pushMike Hommey, Dec 11, 2007
  2. 2/2 Fix some memory leaks in various placesMike Hommey, Dec 11, 2007
  3. 3/2 Fix small memory leaks induced by diff_tree_setup_pathsMike Hommey, Dec 11, 2007
  4. 1/2 Fix XML parser leaks in http-pushMike Hommey, Dec 11, 2007
  5. Junio C HamanoDec 11, 2007
  6. 1/2 Fix XML parser leaks in http-pushMike Hommey, Dec 11, 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.