From 2da2de46a8dc9d44b624c40adb0d6bf698567167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Thu, 24 May 2012 10:44:44 +0200 Subject: Fixed bug #60785 Memory leak in IntlDateFormatter constructor. udat_setCalendar() clones the calendar before it adopts it, so we were leaking the original calendar. Also we now validate the calendar type. --- ext/intl/dateformat/dateformat.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'ext/intl/dateformat') diff --git a/ext/intl/dateformat/dateformat.c b/ext/intl/dateformat/dateformat.c index 6c0c52257b..b399a39fcb 100755 --- a/ext/intl/dateformat/dateformat.c +++ b/ext/intl/dateformat/dateformat.c @@ -99,6 +99,15 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) } INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); + + if (calendar != UCAL_TRADITIONAL && calendar != UCAL_GREGORIAN) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " + "invalid value for calendar type; it must be one of " + "IntlDateFormatter::TRADITIONAL (locale's default calendar) " + "or IntlDateFormatter::GREGORIAN", 0 TSRMLS_CC); + goto error; + } + DATE_FORMAT_METHOD_FETCH_OBJECT; if (DATE_FORMAT_OBJECT(dfo) != NULL) { @@ -142,13 +151,13 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) DATE_FORMAT_OBJECT(dfo) = udat_open(time_type, date_type, locale, timezone_utf16, timezone_utf16_len, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); } - /* Set the calendar if passed */ - if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { - if (calendar) { + if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { + if (calendar != UCAL_TRADITIONAL) { ucal_obj = ucal_open(timezone_utf16, timezone_utf16_len, locale, calendar, &INTL_DATA_ERROR_CODE(dfo)); if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { - udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj ); + udat_setCalendar(DATE_FORMAT_OBJECT(dfo), ucal_obj); + ucal_close(ucal_obj); } else { intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create" ": error opening calendar", 0 TSRMLS_CC); -- cgit v1.2.1