diff options
author | Russell Belfer <rb@github.com> | 2013-06-01 01:13:11 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-06-01 01:13:11 +0400 |
commit | 1a42dd17eb2c35fa572418f5958595cbe297d229 (patch) | |
tree | f135f3788eb20b5ac100519c41c7525f5f830457 /src/pack.c | |
parent | f658dc433cae351e72b1c8b245724eafb43f5844 (diff) |
Mutex init can fail
It is obviously quite a serious problem if this happens, but mutex
initialization can fail and we should detect it. It's a bit like
a memory allocation failure, in that you're probably pretty screwed
if this occurs, but at least we'll catch it.
Diffstat (limited to 'src/pack.c')
-rw-r--r-- | src/pack.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/pack.c b/src/pack.c index a9b835fca..7ce7099e0 100644 --- a/src/pack.c +++ b/src/pack.c @@ -97,7 +97,15 @@ static int cache_init(git_pack_cache *cache) GITERR_CHECK_ALLOC(cache->entries); cache->memory_limit = GIT_PACK_CACHE_MEMORY_LIMIT; - git_mutex_init(&cache->lock); + + if (git_mutex_init(&cache->lock)) { + giterr_set(GITERR_OS, "Failed to initialize pack cache mutex"); + + git__free(cache->entries); + cache->entries = NULL; + + return -1; + } return 0; } @@ -948,7 +956,11 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) p->mtime = (git_time_t)st.st_mtime; p->index_version = -1; - git_mutex_init(&p->lock); + if (git_mutex_init(&p->lock)) { + giterr_set(GITERR_OS, "Failed to initialize packfile mutex"); + git__free(p); + return -1; + } /* see if we can parse the sha1 oid in the packfile name */ if (path_len < 40 || |