Fix locking.

Not sure why I thought defer was lexically scoped. It's not.