Skip to content

Commit 2ba7dbb

Browse files
committed
Resolve static check warnings in example code
Using cppcheck on libgit2 sources indicated two warnings in example code. merge.c was reported as having a memory leak. Fix applied was to `free()` memory pointed to by `parents`. init.c was reported as having a null pointer dereference on variable arg. Function 'usage' was being called with a null variable. Changed supplied parameter to empty string.
1 parent a080037 commit 2ba7dbb

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

examples/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,5 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
244244
}
245245

246246
if (!o->dir)
247-
usage("must specify directory to init", NULL);
247+
usage("must specify directory to init", "");
248248
}

examples/merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, merge_opt
220220
check_lg2(git_repository_head(&head_ref, repo), "failed to get repo HEAD", NULL);
221221
if (resolve_refish(&merge_commit, repo, opts->heads[0])) {
222222
fprintf(stderr, "failed to resolve refish %s", opts->heads[0]);
223+
free(parents);
223224
return -1;
224225
}
225226

0 commit comments

Comments
 (0)