Commit 0f35efeb by Edward Thomson Committed by Patrick Steinhardt

git_pool_init: handle failure cases

Propagate failures caused by pool initialization errors.
parent abfdb8a6
......@@ -63,7 +63,8 @@ static int patch_image_init_fromstr(
memset(out, 0x0, sizeof(patch_image));
git_pool_init(&out->pool, sizeof(git_diff_line));
if (git_pool_init(&out->pool, sizeof(git_diff_line)) < 0)
return -1;
for (start = in; start < in + in_len; start = end) {
end = memchr(start, '\n', in_len - (start - in));
......
......@@ -41,16 +41,21 @@ int git_attr_file__new(
if (git_mutex_init(&attrs->lock) < 0) {
git_error_set(GIT_ERROR_OS, "failed to initialize lock");
git__free(attrs);
return -1;
goto on_error;
}
git_pool_init(&attrs->pool, 1);
if (git_pool_init(&attrs->pool, 1) < 0)
goto on_error;
GIT_REFCOUNT_INC(attrs);
attrs->entry = entry;
attrs->source = source;
*out = attrs;
return 0;
on_error:
git__free(attrs);
return -1;
}
int git_attr_file__clear_rules(git_attr_file *file, bool need_lock)
......
......@@ -391,11 +391,10 @@ int git_attr_cache__init(git_repository *repo)
* hashtable for attribute macros, and string pool
*/
if ((ret = git_strmap_new(&cache->files)) < 0 ||
(ret = git_strmap_new(&cache->macros)) < 0)
(ret = git_strmap_new(&cache->macros)) < 0 ||
(ret = git_pool_init(&cache->pool, 1)) < 0)
goto cancel;
git_pool_init(&cache->pool, 1);
cache = git__compare_and_swap(&repo->attrcache, NULL, cache);
if (cache)
goto cancel; /* raced with another thread, free this but no error */
......
......@@ -1310,7 +1310,8 @@ static int checkout_get_actions(
size_t i, *counts = NULL;
uint32_t *actions = NULL;
git_pool_init(&pathpool, 1);
if (git_pool_init(&pathpool, 1) < 0)
return -1;
if (data->opts.paths.count > 0 &&
git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
......@@ -2526,9 +2527,8 @@ static int checkout_data_init(
git_config_entry_free(conflict_style);
}
git_pool_init(&data->pool, 1);
if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
if ((error = git_pool_init(&data->pool, 1)) < 0 ||
(error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
(error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
(error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
(error = git_buf_puts(&data->target_path, data->opts.target_directory)) < 0 ||
......
......@@ -423,9 +423,8 @@ static git_diff_generated *diff_generated_alloc(
git_attr_session__init(&diff->base.attrsession, repo);
memcpy(&diff->base.opts, &dflt, sizeof(git_diff_options));
git_pool_init(&diff->base.pool, 1);
if (git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) {
if (git_pool_init(&diff->base.pool, 1) < 0 ||
git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) {
git_diff_free(&diff->base);
return NULL;
}
......
......@@ -52,9 +52,8 @@ static git_diff_parsed *diff_parsed_alloc(void)
diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
git_pool_init(&diff->base.pool, 1);
if (git_vector_init(&diff->patches, 0, NULL) < 0 ||
if (git_pool_init(&diff->base.pool, 1) < 0 ||
git_vector_init(&diff->patches, 0, NULL) < 0 ||
git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) {
git_diff_free(&diff->base);
return NULL;
......
......@@ -136,11 +136,10 @@ int git_diff__merge(
return -1;
}
if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0)
if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 ||
git_pool_init(&onto_pool, 1) < 0)
return -1;
git_pool_init(&onto_pool, 1);
for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
git_diff_delta *o = GIT_VECTOR_GET(&onto->deltas, i);
const git_diff_delta *f = GIT_VECTOR_GET(&from->deltas, j);
......
......@@ -411,7 +411,8 @@ int git_index_open(git_index **index_out, const char *index_path)
index = git__calloc(1, sizeof(git_index));
GIT_ERROR_CHECK_ALLOC(index);
git_pool_init(&index->tree_pool, 1);
if (git_pool_init(&index->tree_pool, 1) < 0)
goto fail;
if (index_path != NULL) {
index->index_file_path = git__strdup(index_path);
......
......@@ -897,9 +897,8 @@ static int tree_iterator_init(tree_iterator *iter)
{
int error;
git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry));
if ((error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
if ((error = git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry))) < 0 ||
(error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
return error;
iter->base.flags &= ~GIT_ITERATOR_FIRST_ACCESS;
......@@ -1376,7 +1375,8 @@ static int filesystem_iterator_frame_push(
filesystem_iterator_entry_cmp)) < 0)
goto done;
git_pool_init(&new_frame->entry_pool, 1);
if ((error = git_pool_init(&new_frame->entry_pool, 1)) < 0)
goto done;
/* check if this directory is ignored */
filesystem_iterator_frame_push_ignores(iter, frame_entry, new_frame);
......
......@@ -1810,12 +1810,12 @@ git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo)
diff_list->repo = repo;
git_pool_init(&diff_list->pool, 1);
if (git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
git_merge_diff_list__free(diff_list);
if (git_pool_init(&diff_list->pool, 1) < 0 ||
git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
git_merge_diff_list__free(diff_list);
return NULL;
}
......
......@@ -141,14 +141,11 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
pb = git__calloc(1, sizeof(*pb));
GIT_ERROR_CHECK_ALLOC(pb);
if (git_oidmap_new(&pb->object_ix) < 0)
if (git_oidmap_new(&pb->object_ix) < 0 ||
git_oidmap_new(&pb->walk_objects) < 0 ||
git_pool_init(&pb->object_pool, sizeof(struct walk_object)) < 0)
goto on_error;
if (git_oidmap_new(&pb->walk_objects) < 0)
goto on_error;
git_pool_init(&pb->object_pool, sizeof(struct walk_object));
pb->repo = repo;
pb->nr_threads = 1; /* do not spawn any thread by default */
......
......@@ -238,9 +238,9 @@ int git_pathspec__init(git_pathspec *ps, const git_strarray *paths)
memset(ps, 0, sizeof(*ps));
ps->prefix = git_pathspec_prefix(paths);
git_pool_init(&ps->pool, 1);
if ((error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0)
if ((error = git_pool_init(&ps->pool, 1)) < 0 ||
(error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0)
git_pathspec__clear(ps);
return error;
......@@ -316,7 +316,8 @@ static git_pathspec_match_list *pathspec_match_alloc(
if (!m)
return NULL;
git_pool_init(&m->pool, 1);
if (git_pool_init(&m->pool, 1) < 0)
return NULL;
/* need to keep reference to pathspec and increment refcount because
* failures array stores pointers to the pattern strings of the
......
......@@ -683,7 +683,8 @@ static int refdb_fs_backend__iterator(
iter = git__calloc(1, sizeof(refdb_fs_iter));
GIT_ERROR_CHECK_ALLOC(iter);
git_pool_init(&iter->pool, 1);
if ((error = git_pool_init(&iter->pool, 1)) < 0)
goto out;
if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0)
goto out;
......
......@@ -659,13 +659,11 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
git_revwalk *walk = git__calloc(1, sizeof(git_revwalk));
GIT_ERROR_CHECK_ALLOC(walk);
if (git_oidmap_new(&walk->commits) < 0)
if (git_oidmap_new(&walk->commits) < 0 ||
git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0 ||
git_pool_init(&walk->commit_pool, COMMIT_ALLOC) < 0)
return -1;
if (git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0)
return -1;
git_pool_init(&walk->commit_pool, COMMIT_ALLOC);
walk->get_next = &revwalk_next_unsorted;
walk->enqueue = &revwalk_enqueue_unsorted;
......
......@@ -25,9 +25,8 @@ int git_sortedcache_new(
sc = git__calloc(1, alloclen);
GIT_ERROR_CHECK_ALLOC(sc);
git_pool_init(&sc->pool, 1);
if (git_vector_init(&sc->items, 4, item_cmp) < 0 ||
if (git_pool_init(&sc->pool, 1) < 0 ||
git_vector_init(&sc->items, 4, item_cmp) < 0 ||
git_strmap_new(&sc->map) < 0)
goto fail;
......
......@@ -76,7 +76,8 @@ int git_transaction_new(git_transaction **out, git_repository *repo)
assert(out && repo);
git_pool_init(&pool, 1);
if ((error = git_pool_init(&pool, 1)) < 0)
goto on_error;
tx = git_pool_mallocz(&pool, sizeof(git_transaction));
if (!tx) {
......
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