From 5a8942d7496d7922da699671fa768efeede15324 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Tue, 19 Feb 2008 07:53:15 +0000 Subject: [PATCH] ICU-6076 Fix allocation failure recovery problems. X-SVN-Rev: 23460 --- icu4c/source/i18n/zstrfmt.cpp | 9 ++++++--- icu4c/source/test/cintltst/cbiditst.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/icu4c/source/i18n/zstrfmt.cpp b/icu4c/source/i18n/zstrfmt.cpp index cefb3d33c88..45d811b9d05 100644 --- a/icu4c/source/i18n/zstrfmt.cpp +++ b/icu4c/source/i18n/zstrfmt.cpp @@ -650,8 +650,7 @@ ZoneStringFormat::ZoneStringFormat(const Locale &locale, UErrorCode &status) ZoneStringInfo *zsinfo = new ZoneStringInfo(preferredIdForLocale, strings_mz[typeidx], (TimeZoneTranslationType)type); fZoneStringsTrie.put(strings_mz[typeidx], zsinfo, status); if (U_FAILURE(status)) { - delete zsinfo; - delete strings_mz; + delete []strings_mz; goto error_cleanup; } } @@ -664,7 +663,6 @@ ZoneStringFormat::ZoneStringFormat(const Locale &locale, UErrorCode &status) fMzidToStrings.put(mzid, tmp_mzStrings, status); if (U_FAILURE(status)) { - delete tmp_mzStrings; goto error_cleanup; } @@ -1560,6 +1558,11 @@ ZSFCache::get(const Locale &locale, UErrorCode &status) { if (entry == NULL) { ZoneStringFormat *zsf = new ZoneStringFormat(locale, status); if (U_FAILURE(status)) { + delete zsf; + return NULL; + } + if (zsf == NULL) { + status = U_MEMORY_ALLOCATION_ERROR; return NULL; } // Now add the new entry diff --git a/icu4c/source/test/cintltst/cbiditst.c b/icu4c/source/test/cintltst/cbiditst.c index 517d219df33..0aedf1981ec 100644 --- a/icu4c/source/test/cintltst/cbiditst.c +++ b/icu4c/source/test/cintltst/cbiditst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2007, International Business Machines Corporation and + * Copyright (c) 1997-2008, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /* file name: cbiditst.cpp @@ -1758,6 +1758,10 @@ testMultipleParagraphs(void) { ubidi_orderParagraphsLTR(pBidi, TRUE); ubidi_setPara(pBidi, src, srcSize, UBIDI_RTL, NULL, &errorCode); gotLevels=ubidi_getLevels(pBidi, &errorCode); + if (U_FAILURE(errorCode)) { + log_err("Can't get levels. %s\n", u_errorName(errorCode)); + return; + } for (i=0; i