Commit d900dde4cf84169a52e167182ed3b7a6a1ff151d

Patrick Steinhardt 2019-02-20T10:37:20

Merge pull request #4988 from lhchavez/fix-improbable-odb-initialization-leak Fix a _very_ improbable memory leak in git_odb_new()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/odb.c b/src/odb.c
index 498652c..6ab4bd9 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -443,8 +443,12 @@ int git_odb_new(git_odb **out)
 	git_odb *db = git__calloc(1, sizeof(*db));
 	GIT_ERROR_CHECK_ALLOC(db);
 
-	if (git_cache_init(&db->own_cache) < 0 ||
-		git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) {
+	if (git_cache_init(&db->own_cache) < 0) {
+		git__free(db);
+		return -1;
+	}
+	if (git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) {
+		git_cache_free(&db->own_cache);
 		git__free(db);
 		return -1;
 	}