From: Hokwon Song Date: Mon, 29 Apr 2013 04:21:05 +0000 (+0900) Subject: Fix memory leaks in Locales X-Git-Tag: submit/tizen_2.1/20130514.054102~48^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e7a991cf805ecd3ab72cea8f534ae7cf5eb890a;p=framework%2Fosp%2Fappfw.git Fix memory leaks in Locales Change-Id: I4e4ad806a04099fe422b1c5025e64ff20e5f6bd5 Signed-off-by: Hokwon Song --- diff --git a/src/locales/FLcl_CurrencyImpl.cpp b/src/locales/FLcl_CurrencyImpl.cpp index 158de6f..17002d9 100644 --- a/src/locales/FLcl_CurrencyImpl.cpp +++ b/src/locales/FLcl_CurrencyImpl.cpp @@ -116,19 +116,15 @@ _CurrencyImpl::GetAvailableCurrenciesN(void) if (!currCode.IsEmpty() && !currSymbol.IsEmpty()) { - Currency* pCurr = new (std::nothrow) Currency; + std::unique_ptr< Currency > pCurr(new (std::nothrow) Currency); SysTryReturn(NID_LCL, pCurr, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY)); pCurr->__currencyCodeSymbol = currCode + "_" + currSymbol; - if (!pNewList->Contains(*pCurr)) + if (!pNewList->Contains(*(pCurr.get()))) { - result r = pNewList->Add(*(pCurr)); - if (IsFailed(r)) - { - delete pCurr; - SetLastResult(E_SYSTEM); - return null; - } + result r = pNewList->Add(*(pCurr.get())); + SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "Itis fail to make the currency list."); + pCurr.release(); } } } diff --git a/src/locales/FLcl_DateTimeSymbolsImpl.cpp b/src/locales/FLcl_DateTimeSymbolsImpl.cpp index 65033ee..b0cd103 100644 --- a/src/locales/FLcl_DateTimeSymbolsImpl.cpp +++ b/src/locales/FLcl_DateTimeSymbolsImpl.cpp @@ -349,21 +349,24 @@ _DateTimeSymbolsImpl::GetTimeZoneName(Tizen::Base::String& timeZoneId, int timeZ ClearLastResult(); - if (__pTimeZonesMap && __pTimeZonesMap->GetValuesN(timeZoneId)) + if (__pTimeZonesMap) { std::unique_ptr< IEnumerator >pValueEnum(__pTimeZonesMap->GetValuesN(timeZoneId)); - int i = 0; - String timeZoneName; - while(pValueEnum->MoveNext() == E_SUCCESS) + if (pValueEnum != null) { - if (i++ == timeZoneStyle) + int i = 0; + String timeZoneName; + while(pValueEnum->MoveNext() == E_SUCCESS) { - timeZoneName = *(static_cast (pValueEnum->GetCurrent())); + if (i++ == timeZoneStyle) + { + timeZoneName = *(static_cast (pValueEnum->GetCurrent())); + } } + SetLastResult(E_SUCCESS); + return timeZoneName; } - SetLastResult(E_SUCCESS); - return timeZoneName; } const IcuUnicodeString** pIcuMap = null; diff --git a/src/locales/FLcl_LocaleManagerImpl.cpp b/src/locales/FLcl_LocaleManagerImpl.cpp index e65ad44..61c82ec 100644 --- a/src/locales/FLcl_LocaleManagerImpl.cpp +++ b/src/locales/FLcl_LocaleManagerImpl.cpp @@ -312,18 +312,14 @@ _LocaleManagerImpl::GetAvailableLocalesN(void) Locale ospLocale = _LocaleImpl(*(pIcuLocaleList + i)).GetOspLocale(); if (_LocaleImpl::IsSupported(ospLocale)) { - Locale* pLocale = new (std::nothrow) Locale(ospLocale); + std::unique_ptr< Locale > pLocale(new (std::nothrow) Locale(ospLocale)); SysTryReturn(NID_LCL, pLocale, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY)); - if (!pAvailableLocaleList->Contains(*pLocale)) + if (!pAvailableLocaleList->Contains(*(pLocale.get()))) { - r = pAvailableLocaleList->Add(*pLocale); - if (IsFailed(r)) - { - delete pLocale; - SetLastResult(E_SYSTEM); - return null; - } + r = pAvailableLocaleList->Add(*(pLocale.get())); + SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make the locale list"); + pLocale.release(); } } } @@ -423,12 +419,7 @@ _LocaleManagerImpl::GetAvailableLanguagesFallbackN(void) SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pLanguageMap->Add(*(pLanguageCode.get()), *(pDummyValue.get())); - - if (IsFailed(r)) - { - SetLastResult(E_SYSTEM); - return null; - } + SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make a language list."); pLanguageCode.release(); pDummyValue.release(); } @@ -464,27 +455,30 @@ _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* p while (pIcuTZStr != null) { - String* pTimeZone = new (std::nothrow) String(pIcuTZStr); + std::unique_ptr< String > pTimeZone(new (std::nothrow) String(pIcuTZStr)); SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - if (!pTimeZoneMap->ContainsKey(*pTimeZone) && pTZMap->ContainsKey(*pTimeZone)) + if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get())) && pTZMap->ContainsKey(*(pTimeZone.get()))) { - String* pDummyValue = new (std::nothrow) String(); - r = pTimeZoneMap->Add(*pTimeZone, *pDummyValue); + std::unique_ptr< String > pDummyValue(new (std::nothrow) String()); + SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get())); if (IsFailed(r)) { - delete pTimeZone; - delete pDummyValue; pTZMap->RemoveAll(); + delete pTZMap; SetLastResult(E_SYSTEM); return null; } + pTimeZone.release(); + pDummyValue.release(); } pIcuTZStr = pIcuTZStrList->next(&resultLength, ec); } SetLastResult(E_SUCCESS); pTZMap->RemoveAll(); + delete pTZMap; return pTimeZoneMap.release(); } @@ -552,22 +546,20 @@ _LocaleManagerImpl::GetAvailableTimeZonesFallbackN(void) do { - String* pTimeZone = new (std::nothrow) String(TimeZoneList[index++]); + std::unique_ptr< String > pTimeZone(new (std::nothrow) String(TimeZoneList[index++])); SysTryReturn(NID_LCL, pTimeZone, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - if (!pTimeZoneMap->ContainsKey(*pTimeZone)) + if (!pTimeZoneMap->ContainsKey(*(pTimeZone.get()))) { - String* pDummyValue = new (std::nothrow) String(); + std::unique_ptr< String > pDummyValue (new (std::nothrow) String()); + SysTryReturn(NID_LCL, pDummyValue, null, E_OUT_OF_MEMORY,"[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); - r = pTimeZoneMap->Add(*pTimeZone, *pDummyValue); - if (IsFailed(r)) - { - delete pTimeZone; - delete pDummyValue; - SetLastResult(E_SYSTEM); - return null; - } + r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get())); + SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to make Timezone list."); + + pTimeZone.release(); + pDummyValue.release(); } }while (index < TIMEZONE_MAX);