summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-01-12 19:31:07 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2013-01-12 19:41:30 +0100
commit09e29e47b3ee18888cfb0fc4abd5346b390e70fb (patch)
tree4c6da5172529b1d43e8c6dd078cbc21d99bb6b52 /src
parent0b3aa7beded6ed921a3701059f47b8ebddf064bd (diff)
downloadlibgit2-09e29e47b3ee18888cfb0fc4abd5346b390e70fb.tar.gz
pack: fixes to the cache
The offset should be git_off_t, and we should check the return value of the mutex lock function.
Diffstat (limited to 'src')
-rw-r--r--src/pack.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/pack.c b/src/pack.c
index 3490c8bb9..ddba5d686 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -97,12 +97,14 @@ static int cache_init(git_pack_cache *cache)
return 0;
}
-static git_pack_cache_entry *cache_get(git_pack_cache *cache, size_t offset)
+static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
{
khiter_t k;
git_pack_cache_entry *entry = NULL;
- git_mutex_lock(&cache->lock);
+ if (git_mutex_lock(&cache->lock) < 0)
+ return NULL;
+
k = kh_get(off, cache->entries, offset);
if (k != kh_end(cache->entries)) { /* found it */
entry = kh_value(cache->entries, k);
@@ -150,7 +152,10 @@ static int cache_add(git_pack_cache *cache, git_rawobj *base, git_off_t offset)
entry = new_cache_object(base);
if (entry) {
- git_mutex_lock(&cache->lock);
+ if (git_mutex_lock(&cache->lock) < 0) {
+ giterr_set(GITERR_OS, "failed to lock cache");
+ return -1;
+ }
/* Add it to the cache if nobody else has */
exists = kh_get(off, cache->entries, offset) != kh_end(cache->entries);
if (!exists) {