diff options
author | Martin Ågren <martin.agren@gmail.com> | 2017-11-07 21:39:45 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-08 03:34:00 +0100 |
commit | 4da72644b768b0491110a8ba0aa84d32b6bde41c (patch) | |
tree | be9d8ddc0fc3d78e3d5aa2b80edbf396b7c2b566 /commit.h | |
parent | builtin/merge-base: free commit lists (diff) | |
download | git-4da72644b768b0491110a8ba0aa84d32b6bde41c.tar.xz git-4da72644b768b0491110a8ba0aa84d32b6bde41c.zip |
reduce_heads: fix memory leaks
We currently have seven callers of `reduce_heads(foo)`. Six of them do
not use the original list `foo` again, and actually, all six of those
end up leaking it.
Introduce and use `reduce_heads_replace(&foo)` as a leak-free version of
`foo = reduce_heads(foo)` to fix several of these. Fix the remaining
leaks using `free_commit_list()`.
While we're here, document `reduce_heads()` and mark it as `extern`.
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r-- | commit.h | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -313,7 +313,23 @@ extern int interactive_add(int argc, const char **argv, const char *prefix, int extern int run_add_interactive(const char *revision, const char *patch_mode, const struct pathspec *pathspec); -struct commit_list *reduce_heads(struct commit_list *heads); +/* + * Takes a list of commits and returns a new list where those + * have been removed that can be reached from other commits in + * the list. It is useful for, e.g., reducing the commits + * randomly thrown at the git-merge command and removing + * redundant commits that the user shouldn't have given to it. + * + * This function destroys the STALE bit of the commit objects' + * flags. + */ +extern struct commit_list *reduce_heads(struct commit_list *heads); + +/* + * Like `reduce_heads()`, except it replaces the list. Use this + * instead of `foo = reduce_heads(foo);` to avoid memory leaks. + */ +extern void reduce_heads_replace(struct commit_list **heads); struct commit_extra_header { struct commit_extra_header *next; |