Skip to content

Commit 17641f1

Browse files
authored
Merge pull request libgit2#5526 from libgit2/ethomson/poolinit
git_pool_init: allow the function to fail
2 parents 172a288 + 0f35efe commit 17641f1

18 files changed

+56
-52
lines changed

src/apply.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ static int patch_image_init_fromstr(
6363

6464
memset(out, 0x0, sizeof(patch_image));
6565

66-
git_pool_init(&out->pool, sizeof(git_diff_line));
66+
if (git_pool_init(&out->pool, sizeof(git_diff_line)) < 0)
67+
return -1;
6768

6869
for (start = in; start < in + in_len; start = end) {
6970
end = memchr(start, '\n', in_len - (start - in));

src/attr_file.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,21 @@ int git_attr_file__new(
4141

4242
if (git_mutex_init(&attrs->lock) < 0) {
4343
git_error_set(GIT_ERROR_OS, "failed to initialize lock");
44-
git__free(attrs);
45-
return -1;
44+
goto on_error;
4645
}
4746

48-
git_pool_init(&attrs->pool, 1);
47+
if (git_pool_init(&attrs->pool, 1) < 0)
48+
goto on_error;
49+
4950
GIT_REFCOUNT_INC(attrs);
5051
attrs->entry = entry;
5152
attrs->source = source;
5253
*out = attrs;
5354
return 0;
55+
56+
on_error:
57+
git__free(attrs);
58+
return -1;
5459
}
5560

5661
int git_attr_file__clear_rules(git_attr_file *file, bool need_lock)

src/attrcache.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,10 @@ int git_attr_cache__init(git_repository *repo)
391391
* hashtable for attribute macros, and string pool
392392
*/
393393
if ((ret = git_strmap_new(&cache->files)) < 0 ||
394-
(ret = git_strmap_new(&cache->macros)) < 0)
394+
(ret = git_strmap_new(&cache->macros)) < 0 ||
395+
(ret = git_pool_init(&cache->pool, 1)) < 0)
395396
goto cancel;
396397

397-
git_pool_init(&cache->pool, 1);
398-
399398
cache = git__compare_and_swap(&repo->attrcache, NULL, cache);
400399
if (cache)
401400
goto cancel; /* raced with another thread, free this but no error */

src/checkout.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,8 @@ static int checkout_get_actions(
13101310
size_t i, *counts = NULL;
13111311
uint32_t *actions = NULL;
13121312

1313-
git_pool_init(&pathpool, 1);
1313+
if (git_pool_init(&pathpool, 1) < 0)
1314+
return -1;
13141315

13151316
if (data->opts.paths.count > 0 &&
13161317
git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
@@ -2526,9 +2527,8 @@ static int checkout_data_init(
25262527
git_config_entry_free(conflict_style);
25272528
}
25282529

2529-
git_pool_init(&data->pool, 1);
2530-
2531-
if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
2530+
if ((error = git_pool_init(&data->pool, 1)) < 0 ||
2531+
(error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
25322532
(error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
25332533
(error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
25342534
(error = git_buf_puts(&data->target_path, data->opts.target_directory)) < 0 ||

src/diff_generate.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,8 @@ static git_diff_generated *diff_generated_alloc(
423423
git_attr_session__init(&diff->base.attrsession, repo);
424424
memcpy(&diff->base.opts, &dflt, sizeof(git_diff_options));
425425

426-
git_pool_init(&diff->base.pool, 1);
427-
428-
if (git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) {
426+
if (git_pool_init(&diff->base.pool, 1) < 0 ||
427+
git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) {
429428
git_diff_free(&diff->base);
430429
return NULL;
431430
}

src/diff_parse.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ static git_diff_parsed *diff_parsed_alloc(void)
5252

5353
diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
5454

55-
git_pool_init(&diff->base.pool, 1);
56-
57-
if (git_vector_init(&diff->patches, 0, NULL) < 0 ||
55+
if (git_pool_init(&diff->base.pool, 1) < 0 ||
56+
git_vector_init(&diff->patches, 0, NULL) < 0 ||
5857
git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) {
5958
git_diff_free(&diff->base);
6059
return NULL;

src/diff_tform.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,10 @@ int git_diff__merge(
136136
return -1;
137137
}
138138

139-
if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0)
139+
if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 ||
140+
git_pool_init(&onto_pool, 1) < 0)
140141
return -1;
141142

142-
git_pool_init(&onto_pool, 1);
143-
144143
for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
145144
git_diff_delta *o = GIT_VECTOR_GET(&onto->deltas, i);
146145
const git_diff_delta *f = GIT_VECTOR_GET(&from->deltas, j);

src/index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ int git_index_open(git_index **index_out, const char *index_path)
411411
index = git__calloc(1, sizeof(git_index));
412412
GIT_ERROR_CHECK_ALLOC(index);
413413

414-
git_pool_init(&index->tree_pool, 1);
414+
if (git_pool_init(&index->tree_pool, 1) < 0)
415+
goto fail;
415416

416417
if (index_path != NULL) {
417418
index->index_file_path = git__strdup(index_path);

src/iterator.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,8 @@ static int tree_iterator_init(tree_iterator *iter)
897897
{
898898
int error;
899899

900-
git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry));
901-
902-
if ((error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
900+
if ((error = git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry))) < 0 ||
901+
(error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
903902
return error;
904903

905904
iter->base.flags &= ~GIT_ITERATOR_FIRST_ACCESS;
@@ -1376,7 +1375,8 @@ static int filesystem_iterator_frame_push(
13761375
filesystem_iterator_entry_cmp)) < 0)
13771376
goto done;
13781377

1379-
git_pool_init(&new_frame->entry_pool, 1);
1378+
if ((error = git_pool_init(&new_frame->entry_pool, 1)) < 0)
1379+
goto done;
13801380

13811381
/* check if this directory is ignored */
13821382
filesystem_iterator_frame_push_ignores(iter, frame_entry, new_frame);

src/merge.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,12 +1810,12 @@ git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo)
18101810

18111811
diff_list->repo = repo;
18121812

1813-
git_pool_init(&diff_list->pool, 1);
18141813

1815-
if (git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
1816-
git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
1817-
git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
1818-
git_merge_diff_list__free(diff_list);
1814+
if (git_pool_init(&diff_list->pool, 1) < 0 ||
1815+
git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
1816+
git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
1817+
git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
1818+
git_merge_diff_list__free(diff_list);
18191819
return NULL;
18201820
}
18211821

0 commit comments

Comments
 (0)