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
Fix the revision race check

With commit 62fabf3a65d the revision update was move to a place after the race
check. So we need to check for old_rev > new_rev now.
Merge pull request #1064 from rhafer/race_check

Fix the revision race check