Merge pull request #6219 from apnadkarni/patch-2 Free parent and ref in lg2_commit before returning.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/examples/commit.c b/examples/commit.c
index cd9782d..aedc1af 100644
--- a/examples/commit.c
+++ b/examples/commit.c
@@ -26,7 +26,7 @@
* This does have:
*
* - Example of performing a git commit with a comment
- *
+ *
*/
int lg2_commit(git_repository *repo, int argc, char **argv)
{
@@ -36,10 +36,10 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
git_oid commit_oid,tree_oid;
git_tree *tree;
- git_index *index;
+ git_index *index;
git_object *parent = NULL;
git_reference *ref = NULL;
- git_signature *signature;
+ git_signature *signature;
/* Validate args */
if (argc < 3 || strcmp(opt, "-m") != 0) {
@@ -62,9 +62,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
check_lg2(git_index_write(index), "Could not write index", NULL);;
check_lg2(git_tree_lookup(&tree, repo, &tree_oid), "Error looking up tree", NULL);
-
+
check_lg2(git_signature_default(&signature, repo), "Error creating signature", NULL);
-
+
check_lg2(git_commit_create_v(
&commit_oid,
repo,
@@ -78,7 +78,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
git_index_free(index);
git_signature_free(signature);
- git_tree_free(tree);
+ git_tree_free(tree);
+ git_object_free(parent);
+ git_reference_free(ref);
return error;
}