Fix a couple of lock leaks and add an assert.