utils: Do not unlock a nil lock

If we fail to get a lock for any reason, we should not try to unlock it
during the exception.