Skip to content

Commit d900dde

Browse files
authored
Merge pull request libgit2#4988 from lhchavez/fix-improbable-odb-initialization-leak
Fix a _very_ improbable memory leak in git_odb_new()
2 parents cb150e6 + dd45539 commit d900dde

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/odb.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,12 @@ int git_odb_new(git_odb **out)
443443
git_odb *db = git__calloc(1, sizeof(*db));
444444
GIT_ERROR_CHECK_ALLOC(db);
445445

446-
if (git_cache_init(&db->own_cache) < 0 ||
447-
git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) {
446+
if (git_cache_init(&db->own_cache) < 0) {
447+
git__free(db);
448+
return -1;
449+
}
450+
if (git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) {
451+
git_cache_free(&db->own_cache);
448452
git__free(db);
449453
return -1;
450454
}

0 commit comments

Comments
 (0)