Fix possible error in lock()