refdb_fs: refactor error handling in iterator creation Refactor the error handling in `refdb_fs_backend__iterator` to always return the correct error code returned by the failing function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 7d987b4..c7df6f2 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -681,40 +681,41 @@ static int refdb_fs_backend__iterator_next_name(
static int refdb_fs_backend__iterator(
git_reference_iterator **out, git_refdb_backend *_backend, const char *glob)
{
- int error;
- refdb_fs_iter *iter;
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
+ refdb_fs_iter *iter = NULL;
+ int error;
assert(backend);
if ((error = packed_reload(backend)) < 0)
- return error;
+ goto out;
iter = git__calloc(1, sizeof(refdb_fs_iter));
GIT_ERROR_CHECK_ALLOC(iter);
git_pool_init(&iter->pool, 1);
- if (git_vector_init(&iter->loose, 8, NULL) < 0)
- goto fail;
+ if ((error = git_vector_init(&iter->loose, 8, NULL)) < 0)
+ goto out;
if (glob != NULL &&
- (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL)
- goto fail;
+ (iter->glob = git_pool_strdup(&iter->pool, glob)) == NULL) {
+ error = GIT_ERROR_NOMEMORY;
+ goto out;
+ }
+
+ if ((error = iter_load_loose_paths(backend, iter)) < 0)
+ goto out;
iter->parent.next = refdb_fs_backend__iterator_next;
iter->parent.next_name = refdb_fs_backend__iterator_next_name;
iter->parent.free = refdb_fs_backend__iterator_free;
- if (iter_load_loose_paths(backend, iter) < 0)
- goto fail;
-
*out = (git_reference_iterator *)iter;
- return 0;
-
-fail:
- refdb_fs_backend__iterator_free((git_reference_iterator *)iter);
- return -1;
+out:
+ if (error)
+ refdb_fs_backend__iterator_free((git_reference_iterator *)iter);
+ return error;
}
static bool ref_is_available(