diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-09-12 11:06:59 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-09-12 11:06:59 +0000 |
commit | 4059722376876b65d8b93a13259cd280a9d878b3 (patch) | |
tree | a4a0c2cfeb0ba355b047dbe87232ef72af12b033 /slobrok | |
parent | 6648f89d562f732972df42214e7b0895edf04659 (diff) |
Ensure static `SBEnv` instance is destroyed when exceptions are triggered
Since the instance is declared as `static` it will otherwise be destroyed as part
of the global destructor invocation cycle at exit. Any transitive dependencies
that are also static may or may not be destroyed prior to the `SBEnv` instance
itself, causing undefined behavior.
Diffstat (limited to 'slobrok')
-rw-r--r-- | slobrok/src/apps/slobrok/slobrok.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/slobrok/src/apps/slobrok/slobrok.cpp b/slobrok/src/apps/slobrok/slobrok.cpp index 0588c90d383..b89449e6779 100644 --- a/slobrok/src/apps/slobrok/slobrok.cpp +++ b/slobrok/src/apps/slobrok/slobrok.cpp @@ -84,16 +84,19 @@ App::Main() } catch (const config::ConfigTimeoutException &e) { LOG(error, "config timeout during construction : %s", e.what()); EV_STOPPING("slobrok", "config timeout during construction"); - return 1; + res = 1; } catch (const vespalib::PortListenException &e) { LOG(error, "Failed listening to network port(%d) with protocol(%s): '%s'", e.get_port(), e.get_protocol().c_str(), e.what()); EV_STOPPING("slobrok", "could not listen to our network port"); - return 1; + res = 1; } catch (const std::exception & e) { LOG(error, "unknown exception during construction : %s", e.what()); EV_STOPPING("slobrok", "unknown exception during construction"); - return 2; + res = 2; + } + if (mainobj && !mainobj->isShuttingDown()) { + mainobj->shutdown(); } mainobj.reset(); return res; |