Fixes lock being set on premature returns.

Fix a bug in lock logic introduced in #3095 and #3338.