From 2a483025d9a2276ed09e538a3cd68426879b1470 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Fri, 15 Feb 2008 22:41:39 +0000 Subject: [PATCH] ICU-6183 Fix some rare UCA initialization problems X-SVN-Rev: 23437 --- icu4c/source/i18n/ucol.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/icu4c/source/i18n/ucol.cpp b/icu4c/source/i18n/ucol.cpp index 965635a53b..e8d39077e8 100644 --- a/icu4c/source/i18n/ucol.cpp +++ b/icu4c/source/i18n/ucol.cpp @@ -1224,51 +1224,42 @@ ucol_initUCA(UErrorCode *status) { UMTX_CHECK(NULL, (_staticUCA == NULL), needsInit); if(needsInit) { - UCollator *newUCA = NULL; - UDataMemory *result = udata_openChoice(NULL, UCA_DATA_TYPE, UCA_DATA_NAME, isAcceptableUCA, NULL, status); - - if(U_FAILURE(*status)) { - if (result) { - udata_close(result); - } - uprv_free(newUCA); - } - // init FCD data if (fcdTrieIndex == NULL) { + // The result is constant, until the library is reloaded. fcdTrieIndex = unorm_getFCDTrie(status); ucln_i18n_registerCleanup(UCLN_I18N_UCOL, ucol_cleanup); } - if(result != NULL) { /* It looks like sometimes we can fail to find the data file */ - newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), newUCA, newUCA, status); + UDataMemory *result = udata_openChoice(NULL, UCA_DATA_TYPE, UCA_DATA_NAME, isAcceptableUCA, NULL, status); + + if(U_SUCCESS(*status)){ + UCollator *newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), NULL, NULL, status); if(U_SUCCESS(*status)){ umtx_lock(NULL); if(_staticUCA == NULL) { _staticUCA = newUCA; + newUCA = NULL; UCA_DATA_MEM = result; result = NULL; - newUCA = NULL; } umtx_unlock(NULL); + ucln_i18n_registerCleanup(UCLN_I18N_UCOL, ucol_cleanup); if(newUCA != NULL) { + ucol_close(newUCA); udata_close(result); - uprv_free(newUCA); - } - else { - ucln_i18n_registerCleanup(UCLN_I18N_UCOL, ucol_cleanup); } // Initalize variables for implicit generation - //const UCAConstants *UCAconsts = (UCAConstants *)((uint8_t *)_staticUCA->image + _staticUCA->image->UCAConsts); uprv_uca_initImplicitConstants(status); - //_staticUCA->mapping.getFoldingOffset = _getFoldingOffset; }else{ + ucol_close(newUCA); udata_close(result); - uprv_free(newUCA); - _staticUCA= NULL; } } + else { + udata_close(result); + } } return _staticUCA; }