Browse Source

Solving leaks within Windows

pull/2883/head
Trish Lam 3 years ago
parent
commit
d87c79ac14
2 changed files with 13 additions and 9 deletions
  1. +7
    -9
      cpp/src/phonenumbers/base/memory/singleton_win32.h
  2. +6
    -0
      cpp/src/phonenumbers/phonenumberutil.cc

+ 7
- 9
cpp/src/phonenumbers/base/memory/singleton_win32.h View File

@ -30,14 +30,12 @@ class Singleton {
virtual ~Singleton() {}
static T* GetInstance() {
AcquireSRWLockExclusive(&singleton_lock_);
if (once_init_) {
EnterCriticalSection(&critical_section_);
if (once_init_) {
Init();
once_init_ = false;
}
LeaveCriticalSection(&critical_section_);
Init();
once_init_ = false;
}
ReleaseSRWLockExclusive(&singleton_lock_);
return instance_;
}
@ -49,7 +47,7 @@ class Singleton {
}
static T* instance_; // Leaky singleton.
static CRITICAL_SECTION critical_section_;
static SRWLOCK singleton_lock_;
static bool once_init_;
};
@ -60,8 +58,8 @@ static bool perform_init_crit(CRITICAL_SECTION& cs)
}
template <class T> T* Singleton<T>::instance_;
template <class T> CRITICAL_SECTION Singleton<T>::critical_section_;
template <class T> bool Singleton<T>::once_init_=perform_init_crit(Singleton<T>::critical_section_);
template <class T> SRWLOCK Singleton<T>::singleton_lock_ = SRWLOCK_INIT;
template <class T> bool Singleton<T>::once_init_ = true;
} // namespace phonenumbers
} // namespace i18n


+ 6
- 0
cpp/src/phonenumbers/phonenumberutil.cc View File

@ -888,6 +888,12 @@ PhoneNumberUtil::~PhoneNumberUtil() {
gtl::STLDeleteContainerPairSecondPointers(
country_calling_code_to_region_code_map_->begin(),
country_calling_code_to_region_code_map_->end());
for (std::map<string, PhoneMetadata>::iterator it = region_to_metadata_map_->begin();
it != region_to_metadata_map_->end();
++it) {
it->second.Clear();
}
}
void PhoneNumberUtil::GetSupportedRegions(std::set<string>* regions)


Loading…
Cancel
Save