Commit 53412305 by Carlos Martín Nieto

tree: plug leaks in the tree updater

parent 6ee08d2c
...@@ -1216,22 +1216,29 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli ...@@ -1216,22 +1216,29 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli
{ {
/* Make sure we're replacing something of the same type */ /* Make sure we're replacing something of the same type */
tree_stack_entry *last = git_array_last(stack); tree_stack_entry *last = git_array_last(stack);
const char *basename = git_path_basename(update->path); char *basename = git_path_basename(update->path);
const git_tree_entry *e = git_treebuilder_get(last->bld, basename); const git_tree_entry *e = git_treebuilder_get(last->bld, basename);
if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) { if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) {
git__free(basename);
giterr_set(GITERR_TREE, "Cannot replace '%s' with '%s' at '%s'", giterr_set(GITERR_TREE, "Cannot replace '%s' with '%s' at '%s'",
git_object_type2string(git_tree_entry_type(e)), git_object_type2string(git_tree_entry_type(e)),
git_object_type2string(git_object__type_from_filemode(update->filemode)), git_object_type2string(git_object__type_from_filemode(update->filemode)),
update->path); update->path);
return -1; error = -1;
goto cleanup;
} }
error = git_treebuilder_insert(NULL, last->bld, basename, &update->id, update->filemode); error = git_treebuilder_insert(NULL, last->bld, basename, &update->id, update->filemode);
git__free(basename);
break; break;
} }
case GIT_TREE_UPDATE_REMOVE: case GIT_TREE_UPDATE_REMOVE:
error = git_treebuilder_remove(git_array_last(stack)->bld, git_path_basename(update->path)); {
char *basename = git_path_basename(update->path);
error = git_treebuilder_remove(git_array_last(stack)->bld, basename);
git__free(basename);
break; break;
}
default: default:
giterr_set(GITERR_TREE, "unkown action for update"); giterr_set(GITERR_TREE, "unkown action for update");
error = -1; error = -1;
...@@ -1275,6 +1282,7 @@ cleanup: ...@@ -1275,6 +1282,7 @@ cleanup:
} }
} }
git_buf_free(&component);
git_array_clear(stack); git_array_clear(stack);
git_vector_free(&entries); git_vector_free(&entries);
return error; return error;
......
...@@ -127,7 +127,6 @@ void test_object_tree_update__add_blobs(void) ...@@ -127,7 +127,6 @@ void test_object_tree_update__add_blobs(void)
}; };
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")); cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
entry.mode = GIT_FILEMODE_BLOB; entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92")); cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92"));
...@@ -161,6 +160,8 @@ void test_object_tree_update__add_blobs(void) ...@@ -161,6 +160,8 @@ void test_object_tree_update__add_blobs(void)
cl_assert_equal_oid(&tree_index_id, &tree_updater_id); cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
} }
git_tree_free(base_tree);
} }
void test_object_tree_update__add_conflict(void) void test_object_tree_update__add_conflict(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment