rpc: Fix leveldb iterator leak, and flush before `gettxoutsetinfo`

This fixes an iterator leak resulting in

    bitcoind: db/version_set.cc:789: leveldb::VersionSet::~VersionSet(): Assertion `dummy_versions_.next_ == &dummy_versions_' failed."

exception on shutdown (as well as keeping a copy of the utxo data pinned on disk until next restart).

Also make sure to flush pcoinsTip before calling GetStats() to make sure we apply them to the current height.
As for leveldb, from the documentation: "An iterator operates on a snapshot of the database taken when the iterator is created". I think this means that we can mark the `gettxoutsetinfo` RPC call as thread-safe? 

Only the Flush would need the cs_main lock, after that it can just take its time to summarize the snapshot and clean up the iterator, then return the result.