fix usage of scoped locks

previously they were getting destroyed
immediately because they were not stored in a
temporary scope variable