Skip to content

Commit

Permalink
Fixed bug #62081
Browse files Browse the repository at this point in the history
Constructor of IntlDateFormatter would leak if called twice.

Made calling it more than once error out before starting
using resources.
  • Loading branch information
cataphract committed May 23, 2012
1 parent 51286bd commit 07c0d71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ext/intl/dateformat/dateformat.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)


INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
DATE_FORMAT_METHOD_FETCH_OBJECT; DATE_FORMAT_METHOD_FETCH_OBJECT;

if (DATE_FORMAT_OBJECT(dfo) != NULL) {
intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_create: cannot call constructor twice", 0 TSRMLS_CC);
return;
}

/* Convert pattern (if specified) to UTF-16. */ /* Convert pattern (if specified) to UTF-16. */
if( pattern_str && pattern_str_len>0 ){ if( pattern_str && pattern_str_len>0 ){
intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo));
Expand Down Expand Up @@ -169,6 +176,8 @@ PHP_FUNCTION( datefmt_create )
*/ */
PHP_METHOD( IntlDateFormatter, __construct ) PHP_METHOD( IntlDateFormatter, __construct )
{ {
/* return_value param is being changed, therefore we will always return
* NULL here */
return_value = getThis(); return_value = getThis();
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
} }
Expand Down
14 changes: 14 additions & 0 deletions ext/intl/tests/bug62081.phpt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Bug #62081: IntlDateFormatter leaks memory if called twice
--SKIPIF--
<?php
if (!extension_loaded('intl'))
die('skip intl extension not enabled');
--FILE--
<?php
ini_set('intl.error_level', E_WARNING);
$x = new IntlDateFormatter(1,1,1,1,1);
var_dump($x->__construct(1,1,1,1,1));
--EXPECTF--
Warning: IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice in %s on line %d
NULL

0 comments on commit 07c0d71

Please sign in to comment.