From 37915750651b5db46abfca5fdd4f4ebb33c0e305 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 11 May 2004 20:23:16 +0000 Subject: [PATCH] ICU-2487 fix resource bundle/mem leaks. Add error status. X-SVN-Rev: 15253 --- icu4c/source/common/uresbund.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/icu4c/source/common/uresbund.c b/icu4c/source/common/uresbund.c index bad10e2c4e5..9dc33c507ef 100644 --- a/icu4c/source/common/uresbund.c +++ b/icu4c/source/common/uresbund.c @@ -2225,11 +2225,15 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, ures_close(&bund2); length = uprv_strlen(found); + if(U_SUCCESS(*status)) { int32_t copyLength = uprv_min(length, resultCapacity); if(copyLength>0) { uprv_strncpy(result, found, copyLength); } + if(length == 0) { + *status = U_MISSING_RESOURCE_ERROR; + } } else { length = 0; result[0]=0; @@ -2261,6 +2265,8 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status) locs = ures_openAvailableLocales(path, status); if(U_FAILURE(*status)) { + ures_close(&item); + ures_close(&subItem); return NULL; } @@ -2269,7 +2275,7 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status) while((locale = uenum_next(locs, &locLen, status))) { UResourceBundle *bund = NULL; - UResourceBundle *subPtr = NULL; + UResourceBundle *subPtr = NULL; UErrorCode subStatus = U_ZERO_ERROR; /* don't fail if a bundle is unopenable */ bund = ures_openDirect(path, locale, &subStatus); @@ -2286,8 +2292,10 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status) #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s-%s values: Can't find in %s - skipping. (%s)\n", path?path:"", keyword, locale, u_errorName(subStatus)); - continue; #endif + ures_close(bund); + bund = NULL; + continue; } while((subPtr = ures_getNextResource(&item,&subItem,&subStatus)) @@ -2324,11 +2332,13 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status) } } } + ures_close(bund); } valuesBuf[valuesIndex++] = 0; /* terminate */ ures_close(&item); ures_close(&subItem); + uenum_close(locs); #if defined(URES_TREE_DEBUG) fprintf(stderr, "%s: size %d, #%d\n", u_errorName(*status), valuesIndex, valuesCount);