For most errors, we jump to a goto label that unlocks the ref and returns NULL. However, in none of these error paths would we ever have actually locked the ref. By the time we actually take the lock, we follow a different path that does not ever hit this goto (we rely on verify_lock to unlock if it finds an error). We can just drop the goto completely and return NULL as appropriate. Signed-off-by: Jeff King <peff@xxxxxxxx> --- refs.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/refs.c b/refs.c index 169a46d..fafae7e 100644 --- a/refs.c +++ b/refs.c @@ -2260,7 +2260,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, ref_file = git_path("%s", orig_refname); if (remove_empty_directories(ref_file)) { error("there are still refs under '%s'", orig_refname); - goto error_return; + return NULL; } refname = resolve_ref_unsafe(orig_refname, resolve_flags, lock->old_sha1, &type); @@ -2270,7 +2270,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, if (!refname) { error("unable to resolve reference %s: %s", orig_refname, strerror(errno)); - goto error_return; + return NULL; } missing = is_null_sha1(lock->old_sha1); /* When the ref did not exist and we are creating it, @@ -2281,7 +2281,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, if (missing && !is_refname_available(refname, skip, get_packed_refs(&ref_cache))) { errno = ENOTDIR; - goto error_return; + return NULL; } lock->lk = xcalloc(1, sizeof(struct lock_file)); @@ -2309,7 +2309,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, /* fall through */ default: error("unable to create directory for %s", ref_file); - goto error_return; + return NULL; } lock->lock_fd = hold_lock_file_for_update(lock->lk, ref_file, lflags); @@ -2325,10 +2325,6 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, unable_to_lock_die(ref_file, errno); } return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock; - - error_return: - unlock_ref(lock); - return NULL; } struct ref_lock *lock_any_ref_for_update(const char *refname, -- 2.1.2.596.g7379948 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html