release the lock in case of error