From 22192adbc8b150cf17446936a67d91227e787581 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 2 Aug 2018 10:16:56 +0200 Subject: lib/icu/Init: add class ScopeIcuInit --- src/Main.cxx | 5 +---- src/lib/icu/Init.hxx | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Main.cxx b/src/Main.cxx index f96146336..41a34c0ee 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -466,8 +466,7 @@ MainOrThrow(int argc, char *argv[]) #endif #endif - IcuInit(); - + const ScopeIcuInit icu_init; const ScopeNetInit net_init; #ifdef ENABLE_DBUS @@ -720,8 +719,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) daemonize_finish(); #endif - IcuFinish(); - return EXIT_SUCCESS; } diff --git a/src/lib/icu/Init.hxx b/src/lib/icu/Init.hxx index 95646e314..c26e018ef 100644 --- a/src/lib/icu/Init.hxx +++ b/src/lib/icu/Init.hxx @@ -37,4 +37,18 @@ static inline void IcuFinish() noexcept {} #endif +class ScopeIcuInit { +public: + ScopeIcuInit() { + IcuInit(); + } + + ~ScopeIcuInit() noexcept { + IcuFinish(); + } + + ScopeIcuInit(const ScopeIcuInit &) = delete; + ScopeIcuInit &operator=(const ScopeIcuInit &) = delete; +}; + #endif -- cgit v1.2.3