ICU-9322 Fix some memory check errors in ICU tools

X-SVN-Rev: 31829
This commit is contained in:
Michael Ow 2012-05-17 19:58:22 +00:00
parent 5d2a5e6fa3
commit 671a7be44b
13 changed files with 46 additions and 16 deletions

View File

@ -226,7 +226,7 @@ config/icucross.mk: $(top_builddir)/icudefs.mk $(top_builddir)/Makefile
@(echo 'TOOLBINDIR=$$(cross_buildroot)/bin' ;\ @(echo 'TOOLBINDIR=$$(cross_buildroot)/bin' ;\
echo 'TOOLLIBDIR=$$(cross_buildroot)/lib' ;\ echo 'TOOLLIBDIR=$$(cross_buildroot)/lib' ;\
echo "INVOKE=$(LDLIBRARYPATH_ENVVAR)=$(LIBRARY_PATH_PREFIX)"'$$(TOOLLIBDIR):$$(cross_buildroot)/stubdata:$$(cross_buildroot)/tools/ctestfw:$$$$'"$(LDLIBRARYPATH_ENVVAR)" ;\ echo "INVOKE=$(LDLIBRARYPATH_ENVVAR)=$(LIBRARY_PATH_PREFIX)"'$$(TOOLLIBDIR):$$(cross_buildroot)/stubdata:$$(cross_buildroot)/tools/ctestfw:$$$$'"$(LDLIBRARYPATH_ENVVAR)" ;\
echo "PKGDATA_INVOKE=$(LDLIBRARYPATH_ENVVAR)=$(LIBRARY_PATH_PREFIX)"'$$(cross_buildroot)/stubdata:$$(cross_buildroot)/tools/ctestfw:$$(TOOLLIBDIR):$$$$'"$(LDLIBRARYPATH_ENVVAR) "'$$'"(PKGDATA_INVOKE_OPTS)" ;\ echo "PKGDATA_INVOKE=$(LDLIBRARYPATH_ENVVAR)=$(LIBRARY_PATH_PREFIX)"'$$(cross_buildroot)/stubdata:$$(cross_buildroot)/tools/ctestfw:$$(TOOLLIBDIR):$$$$'"$(LDLIBRARYPATH_ENVVAR) " ;\
echo ) >> $@ echo ) >> $@

View File

@ -1380,6 +1380,8 @@ normal_exit:
fclose(outfile); fclose(outfile);
} }
u_cleanup();
return ret; return ret;
} }

View File

@ -1,7 +1,7 @@
/* /*
******************************************************************************* *******************************************************************************
* *
* Copyright (C) 2001-2011, International Business Machines * Copyright (C) 2001-2012, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
* *
******************************************************************************* *******************************************************************************
@ -743,6 +743,11 @@ U_CFUNC void ucol_initBuffers(UColTokenParser *src, UColTokListHeader *lh, UErro
uprv_memset(t, 0, UCOL_STRENGTH_LIMIT*sizeof(uint32_t)); uprv_memset(t, 0, UCOL_STRENGTH_LIMIT*sizeof(uint32_t));
/* must initialize ranges to avoid memory check warnings */
for (int i = 0; i < UCOL_CE_STRENGTH_LIMIT; i++) {
uprv_memset(Gens[i].ranges, 0, sizeof(Gens[i].ranges));
}
tok->toInsert = 1; tok->toInsert = 1;
t[tok->strength] = 1; t[tok->strength] = 1;

View File

@ -77,8 +77,6 @@ ICUPKGDATA_DIR = $(ICUDATA_DIR)
endif endif
endif endif
endif endif
# This is needed so that make -j2 doesn't complain when invoking pkgdata's make
PKGDATA_INVOKE_OPTS = MAKEFLAGS=
# These are defined here because mh-cygwin-msvc needs to override these values. # These are defined here because mh-cygwin-msvc needs to override these values.
ICUPKGDATA_INSTALL_DIR = $(DESTDIR)$(ICUPKGDATA_DIR) ICUPKGDATA_INSTALL_DIR = $(DESTDIR)$(ICUPKGDATA_DIR)
@ -259,7 +257,7 @@ LIBICUIO = $(LLIBDIR) $(ICULIBS_IO)
# overridden by icucross.mk # overridden by icucross.mk
INVOKE = $(LDLIBRARYPATH_ENVVAR)=$(LIBRARY_PATH_PREFIX)$(LIBDIR):$(top_builddir)/stubdata:$(top_builddir)/tools/ctestfw:$$$(LDLIBRARYPATH_ENVVAR) $(LEAK_CHECKER) INVOKE = $(LDLIBRARYPATH_ENVVAR)=$(LIBRARY_PATH_PREFIX)$(LIBDIR):$(top_builddir)/stubdata:$(top_builddir)/tools/ctestfw:$$$(LDLIBRARYPATH_ENVVAR) $(LEAK_CHECKER)
# prefer stubdata # prefer stubdata
PKGDATA_INVOKE = $(LDLIBRARYPATH_ENVVAR)=$(top_builddir)/stubdata:$(top_builddir)/tools/ctestfw:$(LIBRARY_PATH_PREFIX)$(LIBDIR):$$$(LDLIBRARYPATH_ENVVAR) $(LEAK_CHECKER) $(PKGDATA_INVOKE_OPTS) PKGDATA_INVOKE = $(LDLIBRARYPATH_ENVVAR)=$(top_builddir)/stubdata:$(top_builddir)/tools/ctestfw:$(LIBRARY_PATH_PREFIX)$(LIBDIR):$$$(LDLIBRARYPATH_ENVVAR) $(LEAK_CHECKER)
INSTALLED_INVOKE = $(LDLIBRARYPATH_ENVVAR)=$(libdir):$$$(LDLIBRARYPATH_ENVVAR) INSTALLED_INVOKE = $(LDLIBRARYPATH_ENVVAR)=$(libdir):$$$(LDLIBRARYPATH_ENVVAR)
# Platform-specific setup # Platform-specific setup

View File

@ -217,6 +217,7 @@ static UOption options[]={
extern int extern int
main(int argc, char* argv[]) { main(int argc, char* argv[]) {
int i, n;
char pathBuf[512]; char pathBuf[512];
FileStream *in; FileStream *in;
UNewDataMemory *out; UNewDataMemory *out;
@ -305,6 +306,15 @@ main(int argc, char* argv[]) {
exit(errorCode); exit(errorCode);
} }
/* clean up tags */
for (i = 0; i < MAX_TAG_COUNT; i++) {
for (n = 0; n < MAX_CONV_COUNT; n++) {
if (tags[i].aliasList[n].aliases!=NULL) {
uprv_free(tags[i].aliasList[n].aliases);
}
}
}
return 0; return 0;
} }
@ -1052,8 +1062,9 @@ writeAliasTable(UNewDataMemory *out) {
uprv_free(normalizedStrings); uprv_free(normalizedStrings);
} }
uprv_free(aliasArrLists); uprv_free(uniqueAliasesToConverter);
uprv_free(uniqueAliases); uprv_free(uniqueAliases);
uprv_free(aliasArrLists);
} }
static char * static char *

View File

@ -435,6 +435,8 @@ main(int argc,
} }
} }
u_cleanup();
/* Dont return warnings as a failure */ /* Dont return warnings as a failure */
if (U_SUCCESS(status)) { if (U_SUCCESS(status)) {
return 0; return 0;

View File

@ -139,7 +139,7 @@ static void
cleanupLookahead(ParseState* state) cleanupLookahead(ParseState* state)
{ {
uint32_t i; uint32_t i;
for (i = 0; i < MAX_LOOKAHEAD; i++) for (i = 0; i <= MAX_LOOKAHEAD; i++)
{ {
ustr_deinit(&state->lookahead[i].value); ustr_deinit(&state->lookahead[i].value);
ustr_deinit(&state->lookahead[i].comment); ustr_deinit(&state->lookahead[i].comment);
@ -1764,6 +1764,8 @@ parseInclude(ParseState* state, char *tag, uint32_t startline, const struct UStr
uBuffer = ucbuf_getBuffer(ucbuf,&len,status); uBuffer = ucbuf_getBuffer(ucbuf,&len,status);
result = string_open(state->bundle, tag, uBuffer, len, comment, status); result = string_open(state->bundle, tag, uBuffer, len, comment, status);
ucbuf_close(ucbuf);
uprv_free(pTarget); uprv_free(pTarget);
uprv_free(filename); uprv_free(filename);

View File

@ -1,7 +1,7 @@
/* /*
******************************************************************************* *******************************************************************************
* *
* Copyright (C) 2000-2011, International Business Machines * Copyright (C) 2000-2012, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
* *
******************************************************************************* *******************************************************************************
@ -1173,6 +1173,10 @@ static void bin_close(struct SResource *binres) {
uprv_free(binres->u.fBinaryValue.fData); uprv_free(binres->u.fBinaryValue.fData);
binres->u.fBinaryValue.fData = NULL; binres->u.fBinaryValue.fData = NULL;
} }
if (binres->u.fBinaryValue.fFileName != NULL) {
uprv_free(binres->u.fBinaryValue.fFileName);
binres->u.fBinaryValue.fFileName = NULL;
}
} }
void res_close(struct SResource *res) { void res_close(struct SResource *res) {

View File

@ -1,7 +1,7 @@
/* /*
******************************************************************************* *******************************************************************************
* *
* Copyright (C) 2003-2009, International Business Machines * Copyright (C) 2003-2012, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
* *
******************************************************************************* *******************************************************************************
@ -262,6 +262,8 @@ main(int argc, char* argv[]) {
uprv_free(filename); uprv_free(filename);
u_cleanup();
#endif #endif
return errorCode; return errorCode;

View File

@ -332,6 +332,7 @@ storeMappingData(){
}else{ }else{
/* realloc */ /* realloc */
UChar* newMappingData = (uint16_t*) uprv_malloc(U_SIZEOF_UCHAR * mappingDataCapacity*2); UChar* newMappingData = (uint16_t*) uprv_malloc(U_SIZEOF_UCHAR * mappingDataCapacity*2);
uprv_memset(newMappingData, 0, U_SIZEOF_UCHAR * mappingDataCapacity*2); /* must initialize to avoid memory check warnings */
if(newMappingData == NULL){ if(newMappingData == NULL){
fprintf(stderr, "Could not realloc the mapping data!\n"); fprintf(stderr, "Could not realloc the mapping data!\n");
exit(U_MEMORY_ALLOCATION_ERROR); exit(U_MEMORY_ALLOCATION_ERROR);
@ -650,13 +651,15 @@ generateData(const char *dataDir, const char* bundleName) {
uhash_close(hashTable); uhash_close(hashTable);
} }
#endif #endif
uprv_free(fileName);
} }
#if !UCONFIG_NO_IDNA #if !UCONFIG_NO_IDNA
extern void extern void
cleanUpData(void) { cleanUpData(void) {
uprv_free(mappingData);
utrie_close(sprepTrie); utrie_close(sprepTrie);
uprv_free(sprepTrie); uprv_free(sprepTrie);
} }

View File

@ -1,5 +1,5 @@
## Makefile.in for ICU - tools/icuinfo ## Makefile.in for ICU - tools/icuinfo
## Copyright (c) 1999-2011, International Business Machines Corporation and ## Copyright (c) 1999-2012, International Business Machines Corporation and
## others. All Rights Reserved. ## others. All Rights Reserved.
## Madhu Katragadda ## Madhu Katragadda
@ -31,7 +31,7 @@ DEPS = $(OBJECTS:.o=.d)
# pass some information # pass some information
ICUINFO_OPTS=-i ../../data/out/build/$(ICUDATA_PLATFORM_NAME) -x $(top_builddir)/config/icuinfo.xml -v ICUINFO_OPTS=-i ../../data/out/build/$(ICUDATA_PLATFORM_NAME) -x $(top_builddir)/config/icuinfo.xml -v -K
## List of phony targets ## List of phony targets
.PHONY : all all-local install install-local clean clean-local \ .PHONY : all all-local install install-local clean clean-local \

View File

@ -1,7 +1,7 @@
/* /*
******************************************************************************* *******************************************************************************
* *
* Copyright (C) 2003-2007, International Business Machines * Copyright (C) 2003-2012, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
* *
******************************************************************************* *******************************************************************************
@ -100,6 +100,7 @@ CnvExtClose(NewConverter *cnvData) {
utm_close(extData->fromUTableUChars); utm_close(extData->fromUTableUChars);
utm_close(extData->fromUTableValues); utm_close(extData->fromUTableValues);
utm_close(extData->fromUBytes); utm_close(extData->fromUBytes);
uprv_free(extData);
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
******************************************************************************* *******************************************************************************
* *
* Copyright (C) 2003-2009, International Business Machines * Copyright (C) 2003-2012, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
* *
******************************************************************************* *******************************************************************************
@ -1030,8 +1030,8 @@ ucm_open() {
U_CAPI void U_EXPORT2 U_CAPI void U_EXPORT2
ucm_close(UCMFile *ucm) { ucm_close(UCMFile *ucm) {
if(ucm!=NULL) { if(ucm!=NULL) {
uprv_free(ucm->base); ucm_closeTable(ucm->base);
uprv_free(ucm->ext); ucm_closeTable(ucm->ext);
uprv_free(ucm); uprv_free(ucm);
} }
} }