Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2019-02-17 09:06:58 +0300
committerPatrick Steinhardt <ps@pks.im>2019-05-02 11:22:12 +0300
commit856afc27d03f7632ca8a7ffbc55f8622f2d147cd (patch)
treed5d3901960114b5ae4cd3b0b8155ca9399499103
parent5189beb0d8700dd73680fb97816030ce60fd1a49 (diff)
Fix a _very_ improbable memory leak in git_odb_new()
This change fixes a mostly theoretical memory leak in got_odb_new() that can only manifest if git_cache_init() fails due to running out of memory or not being able to acquire its lock.
-rw-r--r--src/odb.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/odb.c b/src/odb.c
index 6980ca137..6a7e7ca7e 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;
}