diff options
author | lhchavez <lhchavez@lhchavez.com> | 2019-02-16 22:06:58 -0800 |
---|---|---|
committer | lhchavez <lhchavez@lhchavez.com> | 2019-02-16 22:08:49 -0800 |
commit | dd45539d5470bd9a5747118067d9da0403922252 (patch) | |
tree | 7402f36ac10ee4ada1e80f34d5cf7e75be45fb29 /src/odb.c | |
parent | bda0839734bad8351e1dbc9c7beb8ae1f00d831e (diff) | |
download | libgit2-dd45539d5470bd9a5747118067d9da0403922252.tar.gz |
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.
Diffstat (limited to 'src/odb.c')
-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; } |