mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 04:29:31 +00:00
ICU-13207 Fix some resource leaks.
X-SVN-Rev: 40167
This commit is contained in:
parent
cfef2fb339
commit
7d05feb7a6
3 changed files with 30 additions and 34 deletions
|
@ -939,30 +939,30 @@ static CharString *gSearchTZFileResult = NULL;
|
|||
* This function is not thread safe - it uses a global, gSearchTZFileResult, to hold its results.
|
||||
*/
|
||||
static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
|
||||
DIR* dirp = opendir(path);
|
||||
DIR* subDirp = NULL;
|
||||
DIR* dirp = NULL;
|
||||
struct dirent* dirEntry = NULL;
|
||||
|
||||
char* result = NULL;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
/* Save the current path */
|
||||
CharString curpath(path, -1, status);
|
||||
if (U_FAILURE(status)) {
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
dirp = opendir(path);
|
||||
if (dirp == NULL) {
|
||||
return result;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
if (gSearchTZFileResult == NULL) {
|
||||
gSearchTZFileResult = new CharString;
|
||||
if (gSearchTZFileResult == NULL) {
|
||||
return NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
ucln_common_registerCleanup(UCLN_COMMON_PUTIL, putil_cleanup);
|
||||
}
|
||||
|
||||
/* Save the current path */
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
CharString curpath(path, -1, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check each entry in the directory. */
|
||||
while((dirEntry = readdir(dirp)) != NULL) {
|
||||
const char* dirName = dirEntry->d_name;
|
||||
|
@ -971,15 +971,16 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
|
|||
CharString newpath(curpath, status);
|
||||
newpath.append(dirName, -1, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
DIR* subDirp = NULL;
|
||||
if ((subDirp = opendir(newpath.data())) != NULL) {
|
||||
/* If this new path is a directory, make a recursive call with the newpath. */
|
||||
closedir(subDirp);
|
||||
newpath.append('/', status);
|
||||
if (U_FAILURE(status)) {
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
result = searchForTZFile(newpath.data(), tzInfo);
|
||||
/*
|
||||
|
@ -1003,7 +1004,7 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
|
|||
gSearchTZFileResult->clear();
|
||||
gSearchTZFileResult->append(zoneid, -1, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
result = gSearchTZFileResult->data();
|
||||
/* Get out after the first one found. */
|
||||
|
@ -1012,7 +1013,11 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) {
|
|||
}
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
|
||||
cleanupAndReturn:
|
||||
if (dirp) {
|
||||
closedir(dirp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1083,6 +1083,7 @@ static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
|
|||
pathBuf = (char *)uprv_malloc((uprv_strlen(keyPath)+1)*sizeof(char));
|
||||
if(pathBuf == NULL) {
|
||||
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||
ures_close(mainRes);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1747,26 +1747,16 @@ VTimeZone::write(VTZWriter& writer, UErrorCode& status) const {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
UVector *customProps = NULL;
|
||||
UnicodeString icutzprop;
|
||||
UVector customProps(nullptr, uhash_compareUnicodeString, status);
|
||||
if (olsonzid.length() > 0 && icutzver.length() > 0) {
|
||||
customProps = new UVector(uprv_deleteUObject, uhash_compareUnicodeString, status);
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
UnicodeString *icutzprop = new UnicodeString(ICU_TZINFO_PROP);
|
||||
icutzprop->append(olsonzid);
|
||||
icutzprop->append((UChar)0x005B/*'['*/);
|
||||
icutzprop->append(icutzver);
|
||||
icutzprop->append((UChar)0x005D/*']'*/);
|
||||
customProps->addElement(icutzprop, status);
|
||||
if (U_FAILURE(status)) {
|
||||
delete icutzprop;
|
||||
delete customProps;
|
||||
return;
|
||||
}
|
||||
icutzprop.append(olsonzid);
|
||||
icutzprop.append(u'[');
|
||||
icutzprop.append(icutzver);
|
||||
icutzprop.append(u']');
|
||||
customProps.addElement(&icutzprop, status);
|
||||
}
|
||||
writeZone(writer, *tz, customProps, status);
|
||||
delete customProps;
|
||||
writeZone(writer, *tz, &customProps, status);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue