]> granicus.if.org Git - icu/commitdiff
ICU-20802 Need to use LocalMemory in uloc_openKeywordList, not LocalPointer
authorJeff Genovy <29107334+jefgen@users.noreply.github.com>
Sat, 31 Aug 2019 03:44:42 +0000 (20:44 -0700)
committerJeff Genovy <29107334+jefgen@users.noreply.github.com>
Sat, 31 Aug 2019 07:30:12 +0000 (00:30 -0700)
icu4c/source/common/uloc.cpp

index d58bdfa64e99d4088ac9f7a458cf7d6e4a245c2e..6a9bfcfbff5999355546369160c19e8dbace1773 100644 (file)
@@ -1457,22 +1457,19 @@ static const UEnumeration gKeywordsEnum = {
 U_CAPI UEnumeration* U_EXPORT2
 uloc_openKeywordList(const char *keywordList, int32_t keywordListSize, UErrorCode* status)
 {
-    LocalPointer<UKeywordsContext> myContext;
-    LocalPointer<UEnumeration> result;
+    LocalMemory<UKeywordsContext> myContext;
+    LocalMemory<UEnumeration> result;
 
     if (U_FAILURE(*status)) {
         return nullptr;
     }
-    result.adoptInsteadAndCheckErrorCode(static_cast<UEnumeration *>(uprv_malloc(sizeof(UEnumeration))), *status);
-    if (U_FAILURE(*status)) {
+    myContext.adoptInstead(static_cast<UKeywordsContext *>(uprv_malloc(sizeof(UKeywordsContext))));
+    result.adoptInstead(static_cast<UEnumeration *>(uprv_malloc(sizeof(UEnumeration))));
+    if (myContext.isNull() || result.isNull()) {
+        *status = U_MEMORY_ALLOCATION_ERROR;
         return nullptr;
     }
     uprv_memcpy(result.getAlias(), &gKeywordsEnum, sizeof(UEnumeration));
-    
-    myContext.adoptInsteadAndCheckErrorCode(static_cast<UKeywordsContext *>(uprv_malloc(sizeof(UKeywordsContext))), *status);
-    if (U_FAILURE(*status)) {
-        return nullptr;
-    }
     myContext->keywords = static_cast<char *>(uprv_malloc(keywordListSize+1));
     if (myContext->keywords == nullptr) {
         *status = U_MEMORY_ALLOCATION_ERROR;