summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorScott Furry <scott.wl.furry@gmail.com>2019-06-24 14:55:15 -0600
committerScott Furry <scott.wl.furry@gmail.com>2019-06-27 04:59:28 -0600
commit2ba7dbbe35fe8a76f98c9105f0e22507a492d1a8 (patch)
treeed1ac73e69af02c9963f460cc213cbe0aa847ad2 /examples
parenta080037cde55ce3dccdc664b5bfaf4362d67acbb (diff)
downloadlibgit2-2ba7dbbe35fe8a76f98c9105f0e22507a492d1a8.tar.gz
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.
Diffstat (limited to 'examples')
-rw-r--r--examples/init.c2
-rw-r--r--examples/merge.c1
2 files changed, 2 insertions, 1 deletions
diff --git a/examples/init.c b/examples/init.c
index 23044d10d..e9841bc93 100644
--- a/examples/init.c
+++ b/examples/init.c
@@ -244,5 +244,5 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
}
if (!o->dir)
- usage("must specify directory to init", NULL);
+ usage("must specify directory to init", "");
}
diff --git a/examples/merge.c b/examples/merge.c
index 8ddb79b84..25b0a69f6 100644
--- a/examples/merge.c
+++ b/examples/merge.c
@@ -220,6 +220,7 @@ static int create_merge_commit(git_repository *repo, git_index *index, merge_opt
check_lg2(git_repository_head(&head_ref, repo), "failed to get repo HEAD", NULL);
if (resolve_refish(&merge_commit, repo, opts->heads[0])) {
fprintf(stderr, "failed to resolve refish %s", opts->heads[0]);
+ free(parents);
return -1;
}