Fixed memory leak.
authorHokwon Song <hokwon.song@samsung.com>
Tue, 21 May 2013 09:02:04 +0000 (18:02 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Tue, 21 May 2013 09:02:04 +0000 (18:02 +0900)
Change-Id: I74a96ab6b73f4fd6446830036ad6d54f9d8fa204
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/locales/FLclLocaleManager.cpp
src/locales/FLcl_LocaleManagerImpl.cpp

index f2411da..0482744 100644 (file)
@@ -87,11 +87,22 @@ IList*
 LocaleManager::GetAvailableTimeZonesN(void) const
 {
        ClearLastResult();
-       IMap* pTimeZoneMap = _LocaleManagerImpl::GetAvailableTimeZonesN();
-       IList* pTimeZoneList = pTimeZoneMap->GetKeysN();
-       pTimeZoneMap->RemoveAll();
-       delete pTimeZoneMap;    
-       return pTimeZoneList;
+       std::unique_ptr<IMap> pTimeZoneMap(_LocaleManagerImpl::GetAvailableTimeZonesN());
+       std::unique_ptr<IList> pList(pTimeZoneMap->GetKeysN());
+       std::unique_ptr<ArrayList> pArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pArrayList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       pArrayList->Construct();
+
+       for (int i = 0; i < pList->GetCount(); i++)
+       {
+               std::unique_ptr<String> pTz(new (std::nothrow) String(*((String*)(pList->GetAt(i)))));
+               SysTryReturn(NID_LCL, pTz, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               result r = pArrayList->Add(*(pTz.get()));
+               SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to get the tz list.");
+               pTz.release();
+       }
+       return pArrayList.release();
 }
 
 
@@ -99,11 +110,22 @@ IList*
 LocaleManager::GetAvailableTimeZonesN(int rawOffset) const
 {
        ClearLastResult();
-        IMap* pTimeZoneMap =_LocaleManagerImpl::GetAvailableTimeZonesN(rawOffset);
-        IList* pTimeZoneList = pTimeZoneMap->GetKeysN();    
-       pTimeZoneMap->RemoveAll();
-       delete pTimeZoneMap;
-        return pTimeZoneList;
+       std::unique_ptr<IMap> pTimeZoneMap(_LocaleManagerImpl::GetAvailableTimeZonesN(rawOffset));
+       std::unique_ptr<IList> pList(pTimeZoneMap->GetKeysN());
+       std::unique_ptr<ArrayList> pArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pArrayList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       pArrayList->Construct();
+
+       for (int i = 0; i < pList->GetCount(); i++)
+       {
+               std::unique_ptr<String> pTz(new (std::nothrow) String(*((String*)(pList->GetAt(i)))));
+               SysTryReturn(NID_LCL, pTz, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               result r = pArrayList->Add(*(pTz.get()));
+               SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to get the tz list.");
+               pTz.release();
+       }
+       return pArrayList.release();
 }
 
 TimeZone
index 86ba89d..4155f28 100644 (file)
@@ -494,19 +494,18 @@ IMap*
 _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* pIcuTZStrList)
 {
        SysTryReturn(NID_LCL, pIcuTZStrList, null, E_SYSTEM,
-                               "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
+               "[%s] The method cannot proceed due to a severe system error.",GetErrorMessage(E_SYSTEM));
 
-        std::unique_ptr<HashMap, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
-
-        SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
-                        "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
+        std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
+       SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
+               "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
         pTimeZoneMap->Construct();
+
        result r = E_SUCCESS;
        int resultLength = -1;
        UErrorCode ec = U_ZERO_ERROR;
        const char* pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
-       IMap* pTZMap = GetAvailableTimeZonesN();
-
+       std::unique_ptr<IMap> pTZMap(GetAvailableTimeZonesN());
        r = GetLastResult();
        SysTryReturn(NID_LCL, pTZMap, null, r, "[%s] Fail to get available time zone list", GetErrorMessage(r));
 
@@ -520,13 +519,7 @@ _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* p
                        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))
-                       {
-                               pTZMap->RemoveAll();
-                               delete pTZMap;
-                               SetLastResult(E_SYSTEM);
-                               return null;
-                       }
+                       SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "[E_SYSTEM] It is failed to add a TZ into Map.");
                        pTimeZone.release();
                        pDummyValue.release();
                }
@@ -534,8 +527,6 @@ _LocaleManagerImpl::GetAvailableTimeZonesN(U_ICU_NAMESPACE::StringEnumeration* p
                pIcuTZStr = pIcuTZStrList->next(&resultLength, ec);
        }
        SetLastResult(E_SUCCESS);
-       pTZMap->RemoveAll();
-       delete pTZMap;
        return pTimeZoneMap.release();
 }
 
@@ -547,7 +538,7 @@ _LocaleManagerImpl::GetAvailableTimeZonesN(void)
        String tzFilePath(TIMEZONE_LIST_FILE_PATH);
        result r = E_SUCCESS;
 
-       std::unique_ptr<HashMap, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
+       std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
        SysTryCatch(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
                        "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
        r = file.Construct(tzFilePath, "r");
@@ -575,7 +566,7 @@ _LocaleManagerImpl::GetAvailableTimeZonesN(void)
                                        "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
                        r = pTimeZoneMap->Add(*(pTimeZone.get()), *(pDummyValue.get()));
-                       SysTryCatch(NID_LCL, r == E_SUCCESS, , r,"[%s] It is failed to add the tz into the tz map.", GetErrorMessage(r));
+                       SysTryCatch(NID_LCL, r == E_SUCCESS, , r,"[%s] It is failed to make the tz list.", GetErrorMessage(r));
                        pTimeZone.release();
                        pDummyValue.release();
                }
@@ -592,7 +583,7 @@ CATCH:
 IMap*
 _LocaleManagerImpl::GetAvailableTimeZonesFallbackN(void)
 {
-       std::unique_ptr<HashMap, AllElementsDeleter> pTimeZoneMap(new (std::nothrow) HashMap());
+       std::unique_ptr<HashMap> pTimeZoneMap(new (std::nothrow) HashMap(SingleObjectDeleter));
        SysTryReturn(NID_LCL, pTimeZoneMap, null, E_OUT_OF_MEMORY,
                        "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
 
@@ -628,7 +619,10 @@ _LocaleManagerImpl::GetAvailableTimeZonesFallbackN(void)
 IMap*
 _LocaleManagerImpl::GetAvailableTimeZonesN(int rawOffset)
 {
-       return GetAvailableTimeZonesN(U_ICU_NAMESPACE::TimeZone::createEnumeration(rawOffset * _TimeZoneImpl::ONE_MIN_IN_MILLISEC));
+       std::unique_ptr<U_ICU_NAMESPACE::StringEnumeration> pIcuTzList(U_ICU_NAMESPACE::TimeZone::createEnumeration(rawOffset * _TimeZoneImpl::ONE_MIN_IN_MILLISEC));
+       SysTryReturn(NID_LCL, pIcuTzList, null, E_SYSTEM, "[E_SYSTEM] It is failed to get Icu TZ list.");
+       IMap* pTzList =  GetAvailableTimeZonesN(pIcuTzList.get());
+       return pTzList;
 }