From 8e8b6b01f592b9e366203d70802e44d1a6a08e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 4 Apr 2012 13:13:43 +0200 Subject: [PATCH] Clean up valgrind warnings --- src/config_file.c | 1 + src/odb_loose.c | 2 +- src/status.c | 2 ++ src/submodule.c | 3 ++- tests-clar/refs/unicode.c | 13 +++++++------ tests-clar/status/submodules.c | 1 + tests-clar/status/worktree.c | 1 + 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/config_file.c b/src/config_file.c index 60d4c567e..e16606512 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -334,6 +334,7 @@ static int config_get_multivar( var = var->next; } while (var != NULL); + regfree(®ex); } else { /* no regex; go through all the variables */ do { diff --git a/src/odb_loose.c b/src/odb_loose.c index 085df428a..b593d1846 100644 --- a/src/odb_loose.c +++ b/src/odb_loose.c @@ -772,7 +772,7 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const void *data, size_t len, git_otype type) { - int error, header_len; + int error = 0, header_len; git_buf final_path = GIT_BUF_INIT; char header[64]; git_filebuf fbuf = GIT_FILEBUF_INIT; diff --git a/src/status.c b/src/status.c index 88dd5e03b..7cd914f21 100644 --- a/src/status.c +++ b/src/status.c @@ -43,6 +43,8 @@ static int resolve_head_to_tree(git_tree **tree, git_repository *repo) if (git_object_lookup(&obj, repo, git_reference_oid(head), GIT_OBJ_ANY) < 0) goto fail; + git_reference_free(head); + switch (git_object_type(obj)) { case GIT_OBJ_TREE: *tree = (git_tree *)obj; diff --git a/src/submodule.c b/src/submodule.c index be99b86d5..907e43e88 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -182,6 +182,7 @@ static int submodule_from_config( goto fail; sm->refcount++; } + git_buf_free(&name); if (old_sm && ((git_submodule *)old_sm) != sm) { /* TODO: log entry about multiple submodules with same path */ @@ -255,7 +256,7 @@ static int load_submodule_config(git_repository *repo) GITERR_CHECK_ALLOC(smcfg); /* scan index for gitmodules (and .gitmodules entry) */ - if ((error = git_repository_index(&index, repo)) < 0) + if ((error = git_repository_index__weakptr(&index, repo)) < 0) goto cleanup; memset(&gitmodules_oid, 0, sizeof(gitmodules_oid)); max_i = git_index_entrycount(index); diff --git a/tests-clar/refs/unicode.c b/tests-clar/refs/unicode.c index 16d77a4b7..889c85666 100644 --- a/tests-clar/refs/unicode.c +++ b/tests-clar/refs/unicode.c @@ -17,25 +17,26 @@ void test_refs_unicode__cleanup(void) void test_refs_unicode__create_and_lookup(void) { - git_reference *ref, *ref2; + git_reference *ref0, *ref1, *ref2; git_repository *repo2; const char *REFNAME = "refs/heads/" "\305" "ngstr" "\366" "m"; const char *master = "refs/heads/master"; /* Create the reference */ - cl_git_pass(git_reference_lookup(&ref, repo, master)); - cl_git_pass(git_reference_create_oid(&ref, repo, REFNAME, git_reference_oid(ref), 0)); - cl_assert(strcmp(REFNAME, git_reference_name(ref)) == 0); + cl_git_pass(git_reference_lookup(&ref0, repo, master)); + cl_git_pass(git_reference_create_oid(&ref1, repo, REFNAME, git_reference_oid(ref0), 0)); + cl_assert(strcmp(REFNAME, git_reference_name(ref1)) == 0); /* Lookup the reference in a different instance of the repository */ cl_git_pass(git_repository_open(&repo2, "testrepo.git")); cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME)); - cl_assert(git_oid_cmp(git_reference_oid(ref), git_reference_oid(ref2)) == 0); + cl_assert(git_oid_cmp(git_reference_oid(ref1), git_reference_oid(ref2)) == 0); cl_assert(strcmp(REFNAME, git_reference_name(ref2)) == 0); - git_reference_free(ref); + git_reference_free(ref0); + git_reference_free(ref1); git_reference_free(ref2); git_repository_free(repo2); } diff --git a/tests-clar/status/submodules.c b/tests-clar/status/submodules.c index 10caba1d6..969158825 100644 --- a/tests-clar/status/submodules.c +++ b/tests-clar/status/submodules.c @@ -19,6 +19,7 @@ void test_status_submodules__initialize(void) p_rename("submodules/gitmodules", "submodules/.gitmodules"); cl_git_append2file("submodules/.gitmodules", modpath.ptr); + git_buf_free(&modpath); p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git"); } diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index 7a0494ec9..efdf6f41b 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -127,6 +127,7 @@ void test_status_worktree__purged_worktree(void) /* first purge the contents of the worktree */ cl_git_pass(git_buf_sets(&workdir, git_repository_workdir(repo))); cl_git_pass(git_path_direach(&workdir, remove_file_cb, NULL)); + git_buf_free(&workdir); /* now get status */ memset(&counts, 0x0, sizeof(struct status_entry_counts));