Skip to content

Commit

Permalink
Fix small memory leaks induced by diff_tree_setup_paths
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
glandium authored and gitster committed Dec 12, 2007
1 parent b0fe0d7 commit 03b69c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -444,6 +445,7 @@ static struct origin *find_rename(struct scoreboard *sb,
}
}
diff_flush(&diff_opts);
diff_tree_release_paths(&diff_opts);
return porigin;
}

Expand Down Expand Up @@ -1165,7 +1167,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
}
}
diff_flush(&diff_opts);

diff_tree_release_paths(&diff_opts);
return retval;
}

Expand Down
1 change: 1 addition & 0 deletions builtin-reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() */
Expand Down
2 changes: 2 additions & 0 deletions tree-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -342,6 +343,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
choice = p;

/* Update the path we use from now on.. */
diff_tree_release_paths(opt);
opt->paths[0] = xstrdup(p->one->path);
diff_tree_setup_paths(opt->paths, opt);
break;
Expand Down

0 comments on commit 03b69c7

Please sign in to comment.