Ensure we aren't writing to a closed leveldb database

I've been seeing more segfaults recently and I wanted to ensure that we aren't trying to use a leveldb handle after it's been closed.