Clean up valgrind warnings
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
diff --git a/src/config_file.c b/src/config_file.c
index 60d4c56..e166065 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 085df42..b593d18 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 88dd5e0..7cd914f 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 be99b86..907e43e 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 16d77a4..889c856 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 10caba1..9691588 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 7a0494e..efdf6f4 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));