]> granicus.if.org Git - icu/commitdiff
ICU-13530 Use LocalPointer instead of raw new in umutablecptrie.cpp (#59)
authorJeff Genovy <29107334+jefgen@users.noreply.github.com>
Wed, 15 Aug 2018 21:16:08 +0000 (14:16 -0700)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:38 +0000 (14:27 -0700)
Use LocalPointer instead of raw new in umutablecptrie.cpp so that an ErrorCode will be set in the case of out-of-memory (OOM) failures.

icu4c/source/common/umutablecptrie.cpp

index 892ee3fd3c76a4084ede92dd3a06b48d8040b4bd..b1bdb0aabae77c385b70d5e466aff9d0e0d25470 100644 (file)
@@ -1505,12 +1505,12 @@ umutablecptrie_open(uint32_t initialValue, uint32_t errorValue, UErrorCode *pErr
     if (U_FAILURE(*pErrorCode)) {
         return nullptr;
     }
-    MutableCodePointTrie *trie = new MutableCodePointTrie(initialValue, errorValue, *pErrorCode);
+    LocalPointer<MutableCodePointTrie> trie(
+        new MutableCodePointTrie(initialValue, errorValue, *pErrorCode), *pErrorCode);
     if (U_FAILURE(*pErrorCode)) {
-        delete trie;
         return nullptr;
     }
-    return reinterpret_cast<UMutableCPTrie *>(trie);
+    return reinterpret_cast<UMutableCPTrie *>(trie.orphan());
 }
 
 U_CAPI UMutableCPTrie * U_EXPORT2
@@ -1521,13 +1521,12 @@ umutablecptrie_clone(const UMutableCPTrie *other, UErrorCode *pErrorCode) {
     if (other == nullptr) {
         return nullptr;
     }
-    MutableCodePointTrie *clone = new MutableCodePointTrie(
-        *reinterpret_cast<const MutableCodePointTrie *>(other), *pErrorCode);
+    LocalPointer<MutableCodePointTrie> clone(
+        new MutableCodePointTrie(*reinterpret_cast<const MutableCodePointTrie *>(other), *pErrorCode), *pErrorCode);
     if (U_FAILURE(*pErrorCode)) {
-        delete clone;
         return nullptr;
     }
-    return reinterpret_cast<UMutableCPTrie *>(clone);
+    return reinterpret_cast<UMutableCPTrie *>(clone.orphan());
 }
 
 U_CAPI void U_EXPORT2