From 99cb3d5c6ddef3b77d65db7f1981453e2fec690e Mon Sep 17 00:00:00 2001 From: Eric Mader Date: Wed, 4 Dec 2002 02:38:39 +0000 Subject: [PATCH] ICU-2135 fix memory problems in genrb after running through valgrind X-SVN-Rev: 10473 --- icu4c/source/tools/genrb/parse.c | 10 +++++----- icu4c/source/tools/genrb/reslist.c | 8 +++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/icu4c/source/tools/genrb/parse.c b/icu4c/source/tools/genrb/parse.c index e9e51e21fa2..31c2dce5a97 100644 --- a/icu4c/source/tools/genrb/parse.c +++ b/icu4c/source/tools/genrb/parse.c @@ -701,7 +701,7 @@ static struct SResource * realParseTable(struct SResource *table, char *tag, uint32_t startline, UErrorCode *status) { struct SResource *member = NULL; - struct UString *tokenValue; + struct UString *tokenValue=NULL; enum ETokenType token; char subtag[1024]; uint32_t line; @@ -1121,7 +1121,7 @@ parseImport(char *tag, uint32_t startline, UErrorCode *status) char *filename; uint32_t line; char *fullname = NULL; - + int32_t numRead = 0; filename = getInvariantString(&line, status); if (U_FAILURE(*status)) @@ -1196,8 +1196,8 @@ parseImport(char *tag, uint32_t startline, UErrorCode *status) } len = T_FileStream_size(file); - data = uprv_malloc(len); - + data = (uint8_t*)uprv_malloc(len* sizeof(uint8_t)* 3); + uprv_memset(data,0xFF, len *3); /* test for NULL */ if(data == NULL) { @@ -1206,7 +1206,7 @@ parseImport(char *tag, uint32_t startline, UErrorCode *status) return NULL; } - T_FileStream_read (file, data, len); + numRead = T_FileStream_read (file, data, len); T_FileStream_close (file); result = bin_open(bundle, tag, len, data, fullname, status); diff --git a/icu4c/source/tools/genrb/reslist.c b/icu4c/source/tools/genrb/reslist.c index 66e3ccdf328..2546959c6dc 100644 --- a/icu4c/source/tools/genrb/reslist.c +++ b/icu4c/source/tools/genrb/reslist.c @@ -340,7 +340,9 @@ void bundle_write(struct SRBRoot *bundle, const char *outputDir, const char *out } mem = udata_create(outputDir, "res", dataName, &dataInfo, (gIncludeCopyright==TRUE)? U_COPYRIGHT_STRING:NULL, status); - + if(U_FAILURE(status)){ + return; + } pad = calcPadding(bundle->fKeyPoint); usedOffset = sizeof(uint32_t) + bundle->fKeyPoint + pad ; /*this is how much root and keys are taking up*/ @@ -459,7 +461,7 @@ struct SResource *string_open(struct SRBRoot *bundle, char *tag, UChar *value, i } uprv_memcpy(res->u.fString.fChars, value, sizeof(UChar) * (len + 1)); - res->fSize = sizeof(int32_t) + sizeof(UChar) * (len + 1); + res->fSize = sizeof(int32_t) + sizeof(UChar) * (len); return res; } @@ -598,7 +600,7 @@ struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t len res->u.fBinaryValue.fLength = length; res->u.fBinaryValue.fFileName = NULL; if(fileName!=NULL && uprv_strcmp(fileName, "") !=0){ - res->u.fBinaryValue.fFileName = (char*) uprv_malloc(sizeof(char) * uprv_strlen(fileName)); + res->u.fBinaryValue.fFileName = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(fileName)+1)); uprv_strcpy(res->u.fBinaryValue.fFileName,fileName); } if (length > 0) {