Commit a35b3864 by Justin Spahr-Summers

Always check the result of git_mutex_lock

parent c3320aca
...@@ -52,7 +52,11 @@ void *git_cache_get(git_cache *cache, const git_oid *oid) ...@@ -52,7 +52,11 @@ void *git_cache_get(git_cache *cache, const git_oid *oid)
memcpy(&hash, oid->id, sizeof(hash)); memcpy(&hash, oid->id, sizeof(hash));
git_mutex_lock(&cache->lock); if (git_mutex_lock(&cache->lock)) {
giterr_set(GITERR_THREAD, "unable to lock cache mutex");
return NULL;
}
{ {
node = cache->nodes[hash & cache->size_mask]; node = cache->nodes[hash & cache->size_mask];
...@@ -73,12 +77,16 @@ void *git_cache_try_store(git_cache *cache, void *_entry) ...@@ -73,12 +77,16 @@ void *git_cache_try_store(git_cache *cache, void *_entry)
memcpy(&hash, &entry->oid, sizeof(uint32_t)); memcpy(&hash, &entry->oid, sizeof(uint32_t));
/* increase the refcount on this object, because if (git_mutex_lock(&cache->lock)) {
* the cache now owns it */ giterr_set(GITERR_THREAD, "unable to lock cache mutex");
git_cached_obj_incref(entry); return NULL;
}
git_mutex_lock(&cache->lock);
{ {
/* increase the refcount on this object, because
* the cache now owns it */
git_cached_obj_incref(entry);
git_cached_obj *node = cache->nodes[hash & cache->size_mask]; git_cached_obj *node = cache->nodes[hash & cache->size_mask];
if (node == NULL) { if (node == NULL) {
......
...@@ -44,7 +44,10 @@ void git_mwindow_free_all(git_mwindow_file *mwf) ...@@ -44,7 +44,10 @@ void git_mwindow_free_all(git_mwindow_file *mwf)
git_mwindow_ctl *ctl = &mem_ctl; git_mwindow_ctl *ctl = &mem_ctl;
unsigned int i; unsigned int i;
git_mutex_lock(&git__mwindow_mutex); if (git_mutex_lock(&git__mwindow_mutex)) {
giterr_set(GITERR_THREAD, "unable to lock mwindow mutex");
return;
}
/* /*
* Remove these windows from the global list * Remove these windows from the global list
...@@ -221,7 +224,11 @@ unsigned char *git_mwindow_open( ...@@ -221,7 +224,11 @@ unsigned char *git_mwindow_open(
git_mwindow_ctl *ctl = &mem_ctl; git_mwindow_ctl *ctl = &mem_ctl;
git_mwindow *w = *cursor; git_mwindow *w = *cursor;
git_mutex_lock(&git__mwindow_mutex); if (git_mutex_lock(&git__mwindow_mutex)) {
giterr_set(GITERR_THREAD, "unable to lock mwindow mutex");
return NULL;
}
if (!w || !(git_mwindow_contains(w, offset) && git_mwindow_contains(w, offset + extra))) { if (!w || !(git_mwindow_contains(w, offset) && git_mwindow_contains(w, offset + extra))) {
if (w) { if (w) {
w->inuse_cnt--; w->inuse_cnt--;
...@@ -269,7 +276,11 @@ int git_mwindow_file_register(git_mwindow_file *mwf) ...@@ -269,7 +276,11 @@ int git_mwindow_file_register(git_mwindow_file *mwf)
git_mwindow_ctl *ctl = &mem_ctl; git_mwindow_ctl *ctl = &mem_ctl;
int ret; int ret;
git_mutex_lock(&git__mwindow_mutex); if (git_mutex_lock(&git__mwindow_mutex)) {
giterr_set(GITERR_THREAD, "unable to lock mwindow mutex");
return -1;
}
if (ctl->windowfiles.length == 0 && if (ctl->windowfiles.length == 0 &&
git_vector_init(&ctl->windowfiles, 8, NULL) < 0) { git_vector_init(&ctl->windowfiles, 8, NULL) < 0) {
git_mutex_unlock(&git__mwindow_mutex); git_mutex_unlock(&git__mwindow_mutex);
...@@ -288,7 +299,11 @@ int git_mwindow_file_deregister(git_mwindow_file *mwf) ...@@ -288,7 +299,11 @@ int git_mwindow_file_deregister(git_mwindow_file *mwf)
git_mwindow_file *cur; git_mwindow_file *cur;
unsigned int i; unsigned int i;
git_mutex_lock(&git__mwindow_mutex); if (git_mutex_lock(&git__mwindow_mutex)) {
giterr_set(GITERR_THREAD, "unable to lock mwindow mutex");
return -1;
}
git_vector_foreach(&ctl->windowfiles, i, cur) { git_vector_foreach(&ctl->windowfiles, i, cur) {
if (cur == mwf) { if (cur == mwf) {
git_vector_remove(&ctl->windowfiles, i); git_vector_remove(&ctl->windowfiles, i);
...@@ -306,7 +321,11 @@ void git_mwindow_close(git_mwindow **window) ...@@ -306,7 +321,11 @@ void git_mwindow_close(git_mwindow **window)
{ {
git_mwindow *w = *window; git_mwindow *w = *window;
if (w) { if (w) {
git_mutex_lock(&git__mwindow_mutex); if (git_mutex_lock(&git__mwindow_mutex)) {
giterr_set(GITERR_THREAD, "unable to lock mwindow mutex");
return;
}
w->inuse_cnt--; w->inuse_cnt--;
git_mutex_unlock(&git__mwindow_mutex); git_mutex_unlock(&git__mwindow_mutex);
*window = NULL; *window = NULL;
......
...@@ -1025,6 +1025,14 @@ static void *threaded_find_deltas(void *arg) ...@@ -1025,6 +1025,14 @@ static void *threaded_find_deltas(void *arg)
git_cond_signal(&me->pb->progress_cond); git_cond_signal(&me->pb->progress_cond);
git_packbuilder__progress_unlock(me->pb); git_packbuilder__progress_unlock(me->pb);
if (git_mutex_lock(&me->mutex)) {
giterr_set(GITERR_THREAD, "unable to lock packfile condition mutex");
return NULL;
}
while (!me->data_ready)
git_cond_wait(&me->cond, &me->mutex);
/* /*
* We must not set ->data_ready before we wait on the * We must not set ->data_ready before we wait on the
* condition because the main thread may have set it to 1 * condition because the main thread may have set it to 1
...@@ -1033,9 +1041,6 @@ static void *threaded_find_deltas(void *arg) ...@@ -1033,9 +1041,6 @@ static void *threaded_find_deltas(void *arg)
* was initialized to 0 before this thread was spawned * was initialized to 0 before this thread was spawned
* and we reset it to 0 right away. * and we reset it to 0 right away.
*/ */
git_mutex_lock(&me->mutex);
while (!me->data_ready)
git_cond_wait(&me->cond, &me->mutex);
me->data_ready = 0; me->data_ready = 0;
git_mutex_unlock(&me->mutex); git_mutex_unlock(&me->mutex);
} }
...@@ -1168,7 +1173,12 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list, ...@@ -1168,7 +1173,12 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
target->working = 1; target->working = 1;
git_packbuilder__progress_unlock(pb); git_packbuilder__progress_unlock(pb);
git_mutex_lock(&target->mutex); if (git_mutex_lock(&target->mutex)) {
giterr_set(GITERR_THREAD, "unable to lock packfile condition mutex");
git__free(p);
return -1;
}
target->data_ready = 1; target->data_ready = 1;
git_cond_signal(&target->cond); git_cond_signal(&target->cond);
git_mutex_unlock(&target->mutex); git_mutex_unlock(&target->mutex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment