diff options
author | lhchavez <lhchavez@lhchavez.com> | 2019-02-17 09:06:58 +0300 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-05-02 11:22:12 +0300 |
commit | 856afc27d03f7632ca8a7ffbc55f8622f2d147cd (patch) | |
tree | d5d3901960114b5ae4cd3b0b8155ca9399499103 | |
parent | 5189beb0d8700dd73680fb97816030ce60fd1a49 (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.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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; } |