Skip to content

Commit 1afad26

Browse files
authored
Merge pull request libgit2#6219 from apnadkarni/patch-2
Free parent and ref in lg2_commit before returning.
2 parents 4646f1e + aab7c0b commit 1afad26

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

examples/commit.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* This does have:
2727
*
2828
* - Example of performing a git commit with a comment
29-
*
29+
*
3030
*/
3131
int lg2_commit(git_repository *repo, int argc, char **argv)
3232
{
@@ -36,10 +36,10 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
3636

3737
git_oid commit_oid,tree_oid;
3838
git_tree *tree;
39-
git_index *index;
39+
git_index *index;
4040
git_object *parent = NULL;
4141
git_reference *ref = NULL;
42-
git_signature *signature;
42+
git_signature *signature;
4343

4444
/* Validate args */
4545
if (argc < 3 || strcmp(opt, "-m") != 0) {
@@ -62,9 +62,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
6262
check_lg2(git_index_write(index), "Could not write index", NULL);;
6363

6464
check_lg2(git_tree_lookup(&tree, repo, &tree_oid), "Error looking up tree", NULL);
65-
65+
6666
check_lg2(git_signature_default(&signature, repo), "Error creating signature", NULL);
67-
67+
6868
check_lg2(git_commit_create_v(
6969
&commit_oid,
7070
repo,
@@ -78,7 +78,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
7878

7979
git_index_free(index);
8080
git_signature_free(signature);
81-
git_tree_free(tree);
81+
git_tree_free(tree);
82+
git_object_free(parent);
83+
git_reference_free(ref);
8284

8385
return error;
8486
}

0 commit comments

Comments
 (0)