diff options
author | Justin Spahr-Summers <Justin.SpahrSummers@gmail.com> | 2012-12-09 02:31:39 -0800 |
---|---|---|
committer | Justin Spahr-Summers <Justin.SpahrSummers@gmail.com> | 2012-12-09 02:31:39 -0800 |
commit | a35b3864583bd1c98334aa71bb4e4c217ace55aa (patch) | |
tree | 1045996d00b52649b70e929d09114aa606e78842 /src/mwindow.c | |
parent | c3320aca7640386a2cfc0c785560ff4d36851ef9 (diff) | |
download | libgit2-a35b3864583bd1c98334aa71bb4e4c217ace55aa.tar.gz |
Always check the result of git_mutex_lock
Diffstat (limited to 'src/mwindow.c')
-rw-r--r-- | src/mwindow.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/mwindow.c b/src/mwindow.c index 4da5badb6..ee693e4a0 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -44,7 +44,10 @@ void git_mwindow_free_all(git_mwindow_file *mwf) git_mwindow_ctl *ctl = &mem_ctl; 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 @@ -221,7 +224,11 @@ unsigned char *git_mwindow_open( git_mwindow_ctl *ctl = &mem_ctl; 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) { w->inuse_cnt--; @@ -269,7 +276,11 @@ int git_mwindow_file_register(git_mwindow_file *mwf) git_mwindow_ctl *ctl = &mem_ctl; 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 && git_vector_init(&ctl->windowfiles, 8, NULL) < 0) { git_mutex_unlock(&git__mwindow_mutex); @@ -288,7 +299,11 @@ int git_mwindow_file_deregister(git_mwindow_file *mwf) git_mwindow_file *cur; 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) { if (cur == mwf) { git_vector_remove(&ctl->windowfiles, i); @@ -306,7 +321,11 @@ void git_mwindow_close(git_mwindow **window) { git_mwindow *w = *window; 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--; git_mutex_unlock(&git__mwindow_mutex); *window = NULL; |