Fixing service crashes.

StorageDatabase was referenced after its destruction (use shared_ptr to
count references)
Corruption of worker thread list in finalize().
Finished feature 56801948/background-service-crash.