diff --git a/td/telegram/LanguagePackManager.cpp b/td/telegram/LanguagePackManager.cpp index 14cd7dbcd..c34d9b8b9 100644 --- a/td/telegram/LanguagePackManager.cpp +++ b/td/telegram/LanguagePackManager.cpp @@ -21,6 +21,8 @@ namespace td { void LanguagePackManager::start_up() { + std::lock_guard lock(language_packs_mutex_); + manager_count_++; language_pack_ = G()->shared_config().get_option_string("language_pack"); language_code_ = G()->shared_config().get_option_string("language_code"); LOG(INFO) << "Use language pack " << language_pack_ << " with language " << language_code_; @@ -28,6 +30,15 @@ void LanguagePackManager::start_up() { // TODO load language_pack_version from database } +void LanguagePackManager::tear_down() { + std::lock_guard lock(language_packs_mutex_); + manager_count_--; + if (manager_count_ == 0) { + LOG(INFO) << "Clear language packs"; + language_packs_.clear(); + } +} + void LanguagePackManager::on_language_pack_changed() { auto new_language_pack = G()->shared_config().get_option_string("language_pack"); if (new_language_pack == language_pack_) { @@ -427,6 +438,7 @@ void LanguagePackManager::hangup() { stop(); } +int32 LanguagePackManager::manager_count_ = 0; std::mutex LanguagePackManager::language_packs_mutex_; std::unordered_map> LanguagePackManager::language_packs_; diff --git a/td/telegram/LanguagePackManager.h b/td/telegram/LanguagePackManager.h index 42cf7f7ef..b845ae565 100644 --- a/td/telegram/LanguagePackManager.h +++ b/td/telegram/LanguagePackManager.h @@ -72,6 +72,8 @@ class LanguagePackManager : public NetQueryCallback { string language_code_; uint32 generation_ = 0; + static int32 manager_count_; + static std::mutex language_packs_mutex_; static std::unordered_map> language_packs_; @@ -104,6 +106,7 @@ class LanguagePackManager : public NetQueryCallback { void start_up() override; void hangup() override; + void tear_down() override; Container> container_; void send_with_promise(NetQueryPtr query, Promise promise);