Merge pull request #319 from carlosmn/valgrind Fix more memory leaks
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
diff --git a/src/status.c b/src/status.c
index e25e100..97a2855 100644
--- a/src/status.c
+++ b/src/status.c
@@ -267,6 +267,7 @@ int git_status_foreach(git_repository *repo, int (*callback)(const char *, unsig
git_oid_cpy(&e->index_oid, &index_entry->oid);
e->mtime = index_entry->mtime;
}
+ git_index_free(index);
git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE);
git_reference_resolve(&resolved_head_ref, head_ref);
@@ -276,6 +277,7 @@ int git_status_foreach(git_repository *repo, int (*callback)(const char *, unsig
// recurse through tree entries
git_commit_tree(&tree, head_commit);
recurse_tree_entries(tree, &entries, "");
+ git_commit_close(head_commit);
dirent_st.workdir_path_len = strlen(repo->path_workdir);
dirent_st.entry.vector = &entries;
@@ -330,6 +332,7 @@ int git_status_file(unsigned int *status_flags, git_repository *repo, const char
git_oid_cpy(&e->index_oid, &index_entry->oid);
e->mtime = index_entry->mtime;
}
+ git_index_free(index);
// Find file in HEAD
git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE);
@@ -339,6 +342,7 @@ int git_status_file(unsigned int *status_flags, git_repository *repo, const char
git_commit_tree(&tree, head_commit);
recurse_tree_entry(tree, e, path);
+ git_commit_close(head_commit);
// Find file in Workdir
dirent_st.workdir_path_len = strlen(repo->path_workdir);
@@ -346,8 +350,10 @@ int git_status_file(unsigned int *status_flags, git_repository *repo, const char
strcpy(temp_path, repo->path_workdir);
git_futils_direach(temp_path, GIT_PATH_MAX, single_dirent_cb, &dirent_st);
- if ((error = set_status_flags(e)) < GIT_SUCCESS)
+ if ((error = set_status_flags(e)) < GIT_SUCCESS) {
+ free(e);
return git__throw(error, "Nonexistent file");
+ }
*status_flags = e->status_flags;
diff --git a/tests/t17-bufs.c b/tests/t17-bufs.c
index b0269b7..2cbd8c8 100644
--- a/tests/t17-bufs.c
+++ b/tests/t17-bufs.c
@@ -39,6 +39,7 @@ BEGIN_TEST(buf0, "check that resizing works properly")
git_buf_puts(&buf, test_string);
must_be_true(strlen(git_buf_cstr(&buf)) == strlen(test_string) * 2);
+ git_buf_free(&buf);
END_TEST
BEGIN_TEST(buf1, "check that printf works properly")
@@ -51,6 +52,7 @@ BEGIN_TEST(buf1, "check that printf works properly")
git_buf_printf(&buf, "%s %d", "woop", 42);
must_be_true(git_buf_oom(&buf) == 0);
must_be_true(strcmp(git_buf_cstr(&buf), "shoop da 23 woop 42") == 0);
+ git_buf_free(&buf);
END_TEST
BEGIN_SUITE(buffers)