Skip to content

Commit 0fb2464

Browse files
committed
Refactor freeing db backends to not require an additional flag
1 parent 1643e3e commit 0fb2464

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

ext/rugged/rugged_repo.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ static void load_alternates(git_repository *repo, VALUE rb_alternates)
189189
static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, VALUE rb_backend)
190190
{
191191
char *path;
192-
int odb_associated = 0;
193-
int refdb_associated = 0;
194192

195193
git_odb *odb = NULL;
196194
git_odb_backend *odb_backend = NULL;
@@ -217,10 +215,11 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
217215
if (error) goto cleanup;
218216

219217
error = git_odb_add_backend(odb, odb_backend, 1);
220-
if (error)
221-
goto cleanup;
222-
else
223-
odb_associated = 1;
218+
if (error) {
219+
if (odb_backend->free) odb_backend->free(odb_backend);
220+
else git__free(odb_backend);
221+
goto cleanup;
222+
}
224223

225224
error = git_repository_wrap_odb(repo, odb);
226225
if (error) goto cleanup;
@@ -229,10 +228,11 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
229228
if (error) goto cleanup;
230229

231230
error = backend->refdb_backend(&refdb_backend, backend, path);
232-
if (error)
233-
goto cleanup;
234-
else
235-
refdb_associated = 1;
231+
if (error) {
232+
if (refdb_backend->free) odb_backend->free(odb_backend);
233+
else git__free(refdb_backend);
234+
goto cleanup;
235+
}
236236

237237
error = git_refdb_set_backend(refdb, refdb_backend);
238238
if (error) goto cleanup;
@@ -256,9 +256,6 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
256256
git_odb_free(odb);
257257
git_refdb_free(refdb);
258258

259-
if (odb_backend != NULL && !odb_associated && odb_backend->free) odb_backend->free(odb_backend);
260-
if (refdb_backend != NULL && !refdb_associated && refdb_backend->free) refdb_backend->free(refdb_backend);
261-
262259
rugged_exception_check(error);
263260
}
264261

0 commit comments

Comments
 (0)