ICU-6554 Add releasing of allocated memory when uprv_tzname is called.
X-SVN-Rev: 24698
This commit is contained in:
parent
6c1e80795b
commit
f904dc9003
@ -761,6 +761,7 @@ static const char* remapShortTimeZone(const char *stdID, const char *dstID, int3
|
||||
static char* defaultTZBuffer = NULL;
|
||||
static int64_t defaultTZFileSize = 0;
|
||||
static FILE* defaultTZFilePtr = NULL;
|
||||
static UBool defaultTZstatus = FALSE;
|
||||
/*
|
||||
* This method compares the two files given to see if they are a match.
|
||||
* It is currently use to compare two TZ files.
|
||||
@ -937,6 +938,7 @@ uprv_tzname(int n)
|
||||
defaultTZFileSize = 0;
|
||||
|
||||
if (gTimeZoneBufferPtr != NULL && isValidOlsonID(gTimeZoneBufferPtr)) {
|
||||
defaultTZstatus = TRUE;
|
||||
return gTimeZoneBufferPtr;
|
||||
}
|
||||
#endif
|
||||
@ -980,6 +982,18 @@ uprv_tzname(int n)
|
||||
#endif
|
||||
}
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
uprv_free_tzname(void)
|
||||
{
|
||||
/* Only care if memory allocation due to searching for system timezone file. */
|
||||
if (defaultTZstatus == TRUE) {
|
||||
uprv_free(gTimeZoneBufferPtr);
|
||||
gTimeZoneBufferPtr = NULL;
|
||||
defaultTZstatus = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Get and set the ICU data directory --------------------------------------- */
|
||||
|
||||
static char *gDataDirectory = NULL;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1997-2006, International Business Machines
|
||||
* Copyright (C) 1997-2008, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
******************************************************************************
|
||||
@ -211,6 +211,12 @@ U_INTERNAL int32_t U_EXPORT2 uprv_timezone(void);
|
||||
*/
|
||||
U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n);
|
||||
|
||||
/**
|
||||
* If needed, frees the allocated pointer when tzname is called.
|
||||
* @internal
|
||||
*/
|
||||
U_INTERNAL void U_EXPORT2 uprv_free_tzname(void);
|
||||
|
||||
/**
|
||||
* Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
|
||||
* @return the UTC time measured in milliseconds
|
||||
|
@ -420,6 +420,10 @@ TimeZone::TimeZone(const UnicodeString &id)
|
||||
|
||||
TimeZone::~TimeZone()
|
||||
{
|
||||
/* When uprv_tzname() is called, memory might have been
|
||||
allocated for the default timezone name. Release this
|
||||
when the timezone object is deleted. */
|
||||
uprv_free_tzname();
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user