summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2019-02-16 22:06:58 -0800
committerlhchavez <lhchavez@lhchavez.com>2019-02-16 22:08:49 -0800
commitdd45539d5470bd9a5747118067d9da0403922252 (patch)
tree7402f36ac10ee4ada1e80f34d5cf7e75be45fb29 /src/odb.c
parentbda0839734bad8351e1dbc9c7beb8ae1f00d831e (diff)
downloadlibgit2-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.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/odb.c b/src/odb.c
index 498652c79..6ab4bd99a 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;
}