From: Jeff Genovy <29107334+jefgen@users.noreply.github.com> Date: Wed, 15 Aug 2018 21:16:08 +0000 (-0700) Subject: ICU-13530 Use LocalPointer instead of raw new in umutablecptrie.cpp (#59) X-Git-Tag: release-63-rc~116 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01ca8fb5554f1e4f3a722353de44baee3e3fc71b;p=icu ICU-13530 Use LocalPointer instead of raw new in umutablecptrie.cpp (#59) 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. --- diff --git a/icu4c/source/common/umutablecptrie.cpp b/icu4c/source/common/umutablecptrie.cpp index 892ee3fd3c7..b1bdb0aabae 100644 --- a/icu4c/source/common/umutablecptrie.cpp +++ b/icu4c/source/common/umutablecptrie.cpp @@ -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 trie( + new MutableCodePointTrie(initialValue, errorValue, *pErrorCode), *pErrorCode); if (U_FAILURE(*pErrorCode)) { - delete trie; return nullptr; } - return reinterpret_cast(trie); + return reinterpret_cast(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(other), *pErrorCode); + LocalPointer clone( + new MutableCodePointTrie(*reinterpret_cast(other), *pErrorCode), *pErrorCode); if (U_FAILURE(*pErrorCode)) { - delete clone; return nullptr; } - return reinterpret_cast(clone); + return reinterpret_cast(clone.orphan()); } U_CAPI void U_EXPORT2