Fix shutdown in case of errors during initialization
Summary:
This backports prevents an error that could throw a segfault at shutdown
if initialization fails in some cases. This will avoid introducing a bug
when backporting PR11781 in a later diff.
Backport of core PR11783
Depends on D2392
Test Plan:
make check
Further testing will be part of the test plan of PR11781 backport, as I
am not aware of any other method to throw the error.
Reviewers: #bitcoin_abc, deadalnix, jasonbcox
Reviewed By: #bitcoin_abc, jasonbcox
Subscribers: teamcity, schancel
Differential Revision: https://reviews.bitcoinabc.org/D2393