]> granicus.if.org Git - php/commitdiff
- Fixed bug #48227 (NumberFormatter::format leaks memory)
authorFelipe Pena <felipe@php.net>
Sun, 10 May 2009 20:17:22 +0000 (20:17 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 10 May 2009 20:17:22 +0000 (20:17 +0000)
NEWS
ext/intl/formatter/formatter_format.c
ext/intl/tests/bug48227.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index ab6255f71ef60ff8b0d33bc8fb47c043142fa619..93d51b26597049599cedc3d3719567f44da69c4a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ PHP                                                                        NEWS
 
 - Disabled SQLite3::loadExtension for threaded SAPIs. (Scott)
 
+- Fixed bug #48227 (NumberFormatter::format leaks memory). (Felipe)
 
 07 May 2009, PHP 5.3.0 RC 2
 - Upgraded bundled sqlite to version 3.6.13. (Ilia)
index 47e266ff462d0822821eb901f0a657caade4337c..ce1c941e19a8d8c9efcd4cd65925545b6ae5f4f4 100755 (executable)
@@ -54,11 +54,7 @@ PHP_FUNCTION( numfmt_format )
 
        if(type == FORMAT_TYPE_DEFAULT) {
                if(Z_TYPE_PP(number) == IS_STRING) {
-                       SEPARATE_ZVAL_IF_NOT_REF(number);
-                       if ((Z_TYPE_PP(number)=is_numeric_string(Z_STRVAL_PP(number), Z_STRLEN_PP(number), 
-                               &Z_LVAL_PP(number), &Z_DVAL_PP(number), 1)) == 0) {
-                               ZVAL_LONG(*number, 0);
-                       }
+                       convert_scalar_to_number_ex(number);
                }
 
                if(Z_TYPE_PP(number) == IS_LONG) {
diff --git a/ext/intl/tests/bug48227.phpt b/ext/intl/tests/bug48227.phpt
new file mode 100644 (file)
index 0000000..8f633c7
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #48227 (NumberFormatter::format leaks memory)
+--FILE--
+<?php
+
+$x = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
+var_dump($x->format(''));
+var_dump($x->format(1));
+var_dump($x->format(NULL));
+var_dump($x->format($x));
+
+?>
+--EXPECTF--
+string(1) "0"
+string(1) "1"
+string(1) "0"
+
+Notice: Object of class NumberFormatter could not be converted to int in %s on line %d
+string(1) "1"