From 948431aa013b010ccf6b7f6811da9209d784c1a0 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 5 Jan 2012 15:00:46 -0800 Subject: [PATCH 1/3] Remove repo open immediately after init in test Calling git_repository_open immediately after git_repository_init results in memory leaks. --- tests-clay/object/commit/commitstagedfile.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests-clay/object/commit/commitstagedfile.c b/tests-clay/object/commit/commitstagedfile.c index fd149bfc3..764013b38 100644 --- a/tests-clay/object/commit/commitstagedfile.c +++ b/tests-clay/object/commit/commitstagedfile.c @@ -7,7 +7,6 @@ void test_object_commit_commitstagedfile__initialize(void) { cl_fixture("treebuilder"); cl_git_pass(git_repository_init(&repo, "treebuilder/", 0)); - cl_git_pass(git_repository_open(&repo, "treebuilder/.git")); cl_assert(repo != NULL); } From 2d8405025d2037ab5d474b5bb5fbff7b346adce2 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 5 Jan 2012 15:03:42 -0800 Subject: [PATCH 2/3] Throw first error in chain, not rethrow. This is the first time this error is throw, so use git__throw instead of git__rethrow. --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 1338ef3b1..a0ae4cb5b 100644 --- a/src/config.c +++ b/src/config.c @@ -120,7 +120,7 @@ int git_config_add_file(git_config *cfg, git_config_file *file, int priority) assert(cfg && file); if ((error = file->open(file)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to open config file"); + return git__throw(error, "Failed to open config file"); internal = git__malloc(sizeof(file_internal)); if (internal == NULL) From fa3cb0dae079f0f0d4b3f7e6e5eb560627e97eac Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 5 Jan 2012 15:15:43 -0800 Subject: [PATCH 3/3] Fix memory leak in git_index_remove. Missed freeing the entry. --- src/index.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.c b/src/index.c index 9f9a08f0d..9e88012bb 100644 --- a/src/index.c +++ b/src/index.c @@ -510,6 +510,7 @@ int git_index_append2(git_index *index, const git_index_entry *source_entry) int git_index_remove(git_index *index, int position) { + int error; git_index_entry *entry; git_vector_sort(&index->entries); @@ -517,7 +518,12 @@ int git_index_remove(git_index *index, int position) if (entry != NULL) git_tree_cache_invalidate_path(index->tree, entry->path); - return git_vector_remove(&index->entries, (unsigned int)position); + error = git_vector_remove(&index->entries, (unsigned int)position); + + if (error == GIT_SUCCESS) + index_entry_free(entry); + + return error; } int git_index_find(git_index *index, const char *path)