Skip to content

Commit 08a0746

Browse files
committed
ICU-23097 Fix memory leak while fail
1 parent e3e8153 commit 08a0746

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

icu4c/source/common/lstmbe.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,15 @@ U_CAPI const LSTMData* U_EXPORT2 CreateLSTMDataForScript(UScriptCode script, UEr
809809

810810
U_CAPI const LSTMData* U_EXPORT2 CreateLSTMData(UResourceBundle* rb, UErrorCode& status)
811811
{
812-
return new LSTMData(rb, status);
812+
if (U_FAILURE(status)) {
813+
return nullptr;
814+
}
815+
const LSTMData* result = new LSTMData(rb, status);
816+
if (U_FAILURE(status)) {
817+
delete result;
818+
return nullptr;
819+
}
820+
return result;
813821
}
814822

815823
U_CAPI const LanguageBreakEngine* U_EXPORT2

0 commit comments

Comments
 (0)