summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-03-07 16:26:51 +0100
committerVicent Marti <vicent@github.com>2014-03-07 16:26:51 +0100
commit0d95f6ec764e6f709eb44b42b4e4e523abf51824 (patch)
tree7ac45d3d7598966459e5fcb57e05fe790564cef5 /src/commit.c
parentc81e4adfd779a5bf8dd91539dda2dc0636abfc9d (diff)
parentae32c54e5806cf8517beeb057cf640ed346508eb (diff)
downloadlibgit2-0d95f6ec764e6f709eb44b42b4e4e523abf51824.tar.gz
Merge pull request #2169 from libgit2/valgrind
Plug leaks
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/commit.c b/src/commit.c
index 2f5a5b51e..255debe82 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -455,19 +455,18 @@ int git_commit_nth_gen_ancestor(
assert(ancestor && commit);
- current = (git_commit *)commit;
+ if (git_object_dup((git_object **) &current, (git_object *) commit) < 0)
+ return -1;
- if (n == 0)
- return git_commit_lookup(
- ancestor,
- commit->object.repo,
- git_object_id((const git_object *)commit));
+ if (n == 0) {
+ *ancestor = current;
+ return 0;
+ }
while (n--) {
- error = git_commit_parent(&parent, (git_commit *)current, 0);
+ error = git_commit_parent(&parent, current, 0);
- if (current != commit)
- git_commit_free(current);
+ git_commit_free(current);
if (error < 0)
return error;