@matheusbsbs / matheus-bagliano / commits / 03b69c7606
Fork 0

Fix small memory leaks induced by diff_tree_setup_paths

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mike Hommey committed Dec 11, 2007 at 22:59 UTC 03b69c7606267bc978c69cf88fcd7a8edf8175bc
3 files changed +6 -1
builtin-blame.c
+3 -1
@@ -388,6 +388,7 @@ static struct origin *find_origin(struct scoreboard *sb,
388 }
389 }
390 diff_flush(&diff_opts);
391 + diff_tree_release_paths(&diff_opts);
392 if (porigin) {
393 /*
394 * Create a freestanding copy that is not part of
@@ -444,6 +445,7 @@ static struct origin *find_rename(struct scoreboard *sb,
445 }
446 }
447 diff_flush(&diff_opts);
448 + diff_tree_release_paths(&diff_opts);
449 return porigin;
450 }
451
@@ -1165,7 +1167,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
1167 }
1168 }
1169 diff_flush(&diff_opts);
1168 -
1170 + diff_tree_release_paths(&diff_opts);
1171 return retval;
1172 }
1173
builtin-reset.c
+1
@@ -158,6 +158,7 @@ static int read_from_tree(const char *prefix, const char **argv,
158 return 1;
159 diffcore_std(&opt);
160 diff_flush(&opt);
161 + diff_tree_release_paths(&opt);
162
163 if (!index_was_discarded)
164 /* The index is still clobbered from do_diff_cache() */
tree-diff.c
+2
@@ -326,6 +326,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
326 die("unable to set up diff options to follow renames");
327 diff_tree(t1, t2, base, &diff_opts);
328 diffcore_std(&diff_opts);
329 + diff_tree_release_paths(&diff_opts);
330
331 /* Go through the new set of filepairing, and see if we find a more interesting one */
332 for (i = 0; i < q->nr; i++) {
@@ -342,6 +343,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
343 choice = p;
344
345 /* Update the path we use from now on.. */
346 + diff_tree_release_paths(opt);
347 opt->paths[0] = xstrdup(p->one->path);
348 diff_tree_setup_paths(opt->paths, opt);
349 break;