Fix some issues from the last Coverity scan

Fix some issues from the last coverity scan. Most of these are cases where an early return could bypass a call to `git_mutex_unlock` (with one change just to make two similar functions actually have parallel construction).