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.
Merge pull request #1061 from vuntz/fix-utils-unlock

utils: Do not unlock a nil lock