From b2e361cc5e5965d01ef4c033a14ecb61c8523dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 16 Jun 2011 20:22:05 +0200 Subject: [PATCH 1/3] Plug two leaks in config writing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- src/config_file.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/config_file.c b/src/config_file.c index 916b4d081..519936124 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -986,10 +986,19 @@ static int config_write(diskfile_backend *cfg, cvar_t *var) break; } } else { + int cmp; + pre_end = cfg->reader.read_ptr; error = parse_variable(cfg, &var_name, &var_value); - if (error < GIT_SUCCESS || strcasecmp(var->name, var_name)) + if (error == GIT_SUCCESS) + cmp = strcasecmp(var->name, var_name); + + free(var_name); + free(var_value); + + if (error < GIT_SUCCESS || cmp) break; + post_start = cfg->reader.read_ptr; } @@ -1060,6 +1069,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var) else error = git_filebuf_commit(&file); + gitfo_free_buf(&cfg->reader.buffer); return error; } From 038d2fc343192380bdb88047a1a2fdba8bd90255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 16 Jun 2011 20:24:51 +0200 Subject: [PATCH 2/3] Plug leaks in the repo discovery tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- tests/t12-repo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/t12-repo.c b/tests/t12-repo.c index d4038696a..3447f2b22 100644 --- a/tests/t12-repo.c +++ b/tests/t12-repo.c @@ -355,6 +355,7 @@ BEGIN_TEST(discover0, "test discover") must_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1)); must_pass(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs)); + git_repository_free(repo); must_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0)); must_pass(gitfo_mkdir_recurs(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); @@ -402,6 +403,7 @@ BEGIN_TEST(discover0, "test discover") must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path)); rmdir_recurs(DISCOVER_FOLDER); + git_repository_free(repo); END_TEST BEGIN_SUITE(repository) From 3d5a02b653cfa07ffda7e136a94130e14935ee6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 16 Jun 2011 20:30:40 +0200 Subject: [PATCH 3/3] Plug an index leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test wasn't updated when repos lost ownership of indices Signed-off-by: Carlos Martín Nieto --- tests/t06-index.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/t06-index.c b/tests/t06-index.c index 51f89363e..27819c02a 100644 --- a/tests/t06-index.c +++ b/tests/t06-index.c @@ -208,6 +208,7 @@ BEGIN_TEST(add0, "add a new file to the index") /* And the built-in hashing mechanism worked as expected */ must_be_true(git_oid_cmp(&id1, &entry->oid) == 0); + git_index_free(index); git_repository_free(repo); rmdir_recurs(TEMP_REPO_FOLDER); END_TEST