Move an auto variable back into a scoped lock.

Fix for conceivable race condition revealed by nikb.

Even if the problem is not possible now, the lock should surround that access.