ICU-7789 ICU4C memory allocation function cleanup. 4.5.2 BRS task.

X-SVN-Rev: 28714
This commit is contained in:
Andy Heninger 2010-09-27 23:52:31 +00:00
parent b38c190914
commit 633cd9763a
3 changed files with 14 additions and 16 deletions

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 2005-2009, International Business Machines
* Copyright (C) 2005-2010, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
@ -1262,7 +1262,7 @@ uint8_t *CharsetRecog_IBM420_ar::unshape(const uint8_t *inputBytes, int32_t inpu
uint8_t *CharsetRecog_IBM420_ar::unshapeLamAlef(const uint8_t *inputBytes, int32_t inputBytesLength, int32_t &length) {
int32_t bigBufferLength = inputBytesLength * 2;
uint8_t *bigBuffer = new uint8_t[bigBufferLength];
uint8_t *bigBuffer = (uint8_t *)uprv_malloc(bigBufferLength);
uint8_t *resultBuffer = NULL;
if (bigBuffer != NULL) {
@ -1279,14 +1279,14 @@ uint8_t *CharsetRecog_IBM420_ar::unshapeLamAlef(const uint8_t *inputBytes, int32
}
length = bufferIndex;
resultBuffer = new uint8_t[length];
resultBuffer = (uint8_t *)uprv_malloc(length);
if (resultBuffer != NULL) {
uprv_memcpy(resultBuffer, bigBuffer, length);
}
}
if (bigBuffer != NULL) {
delete [] bigBuffer;
uprv_free(bigBuffer);
}
return resultBuffer;
@ -1294,7 +1294,7 @@ uint8_t *CharsetRecog_IBM420_ar::unshapeLamAlef(const uint8_t *inputBytes, int32
void CharsetRecog_IBM420_ar::matchFinish(InputText *textIn) {
if (deleteBuffer) {
delete [] textIn->fInputBytes;
uprv_free(textIn->fInputBytes);
textIn->fInputBytes = prev_fInputBytes;
textIn->fInputLen = prev_fInputBytesLength;

View file

@ -10,6 +10,7 @@
#if !UCONFIG_NO_FORMATTING
#include "unicode/utypes.h"
#include "unicode/fieldpos.h"
#include "unicode/fpositer.h"
@ -18,7 +19,7 @@ U_NAMESPACE_BEGIN
// utility FieldPositionHandler
// base class, null implementation
class FieldPositionHandler {
class FieldPositionHandler: public UMemory {
public:
virtual ~FieldPositionHandler();
virtual void addAttribute(int32_t id, int32_t start, int32_t limit);

View file

@ -496,13 +496,12 @@ TimeUnitFormat::readFromCurrentLocale(EStyle style, const char* key, UErrorCode&
}
MessageFormat** formatters = (MessageFormat**)countToPatterns->get(pluralCount);
if (formatters == NULL) {
// formatters = new MessageFormat*[kTotal];
formatters = (MessageFormat**)uprv_malloc(2*sizeof(MessageFormat*));
formatters = (MessageFormat**)uprv_malloc(kTotal*sizeof(MessageFormat*));
formatters[kFull] = NULL;
formatters[kAbbreviate] = NULL;
countToPatterns->put(pluralCount, formatters, err);
if (U_FAILURE(err)) {
delete [] formatters;
uprv_free(formatters);
}
}
if (U_SUCCESS(err)) {
@ -632,13 +631,12 @@ TimeUnitFormat::searchInLocaleChain(EStyle style, const char* key,
}
MessageFormat** formatters = (MessageFormat**)countToPatterns->get(srcPluralCount);
if (formatters == NULL) {
//formatters = new MessageFormat*[kTotal];
formatters = (MessageFormat**)uprv_malloc(2*sizeof(MessageFormat*));
formatters = (MessageFormat**)uprv_malloc(kTotal*sizeof(MessageFormat*));
formatters[kFull] = NULL;
formatters[kAbbreviate] = NULL;
countToPatterns->put(srcPluralCount, formatters, err);
if (U_FAILURE(err)) {
delete [] formatters;
uprv_free(formatters);
delete messageFormat;
}
}
@ -693,7 +691,7 @@ TimeUnitFormat::searchInLocaleChain(EStyle style, const char* key,
formatters[kAbbreviate] = NULL;
countToPatterns->put(srcPluralCount, formatters, err);
if (U_FAILURE(err)) {
delete [] formatters;
uprv_free(formatters);
delete messageFormat;
}
}
@ -774,15 +772,14 @@ TimeUnitFormat::copyHash(const Hashtable* source, Hashtable* target, UErrorCode&
const UnicodeString* key = (UnicodeString*)keyTok.pointer;
const UHashTok valueTok = element->value;
const MessageFormat** value = (const MessageFormat**)valueTok.pointer;
//MessageFormat** newVal = new MessageFormat*[kTotal];
MessageFormat** newVal = (MessageFormat**)uprv_malloc(2*sizeof(MessageFormat*));
MessageFormat** newVal = (MessageFormat**)uprv_malloc(kTotal*sizeof(MessageFormat*));
newVal[0] = (MessageFormat*)value[0]->clone();
newVal[1] = (MessageFormat*)value[1]->clone();
target->put(UnicodeString(*key), newVal, status);
if ( U_FAILURE(status) ) {
delete newVal[0];
delete newVal[1];
delete [] newVal;
uprv_free(newVal);
return;
}
}