Delete settings engine streams safely

Only delete settings engine streams after database commits.

Fix a few other minor bugs along the way that probably aren't worth their own pull request (UI thread issues that could rarely occur, minor correctness things, and ensure logutil is initialized before we could ever call ExitOnFailure).
This never gets set to true but there is a `::LeaveCriticalSection()` call a few lines down. Also, there is an `ExitOnFailure()` possible that would bypass the leave. It seems like something is cross here. You might want to look at it.