@@ -189,8 +189,6 @@ static void load_alternates(git_repository *repo, VALUE rb_alternates)
189
189
static void rugged_repo_new_with_backend (git_repository * * repo , VALUE rb_path , VALUE rb_backend )
190
190
{
191
191
char * path ;
192
- int odb_associated = 0 ;
193
- int refdb_associated = 0 ;
194
192
195
193
git_odb * odb = NULL ;
196
194
git_odb_backend * odb_backend = NULL ;
@@ -217,10 +215,11 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
217
215
if (error ) goto cleanup ;
218
216
219
217
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
+ }
224
223
225
224
error = git_repository_wrap_odb (repo , odb );
226
225
if (error ) goto cleanup ;
@@ -229,10 +228,11 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
229
228
if (error ) goto cleanup ;
230
229
231
230
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
+ }
236
236
237
237
error = git_refdb_set_backend (refdb , refdb_backend );
238
238
if (error ) goto cleanup ;
@@ -256,9 +256,6 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
256
256
git_odb_free (odb );
257
257
git_refdb_free (refdb );
258
258
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
-
262
259
rugged_exception_check (error );
263
260
}
264
261
0 commit comments