r12221: Fix error code paths that can potentially leave a dangling lock.