com php-src: Use stack memory here to avoid mem leak: ext/standard/math.c

From: Date: Mon, 03 Mar 2014 08:39:29 +0000
Subject: com php-src: Use stack memory here to avoid mem leak: ext/standard/math.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-77837@lists.php.net to get a copy of this message
Commit: be4878edd008a3376bfe1a60bee03cded497ad5f Author: Xinchen Hui <laruence@gmail.com> Mon, 3 Mar 2014 16:39:29 +0800 Parents: b07d5913dd734eae7a2fd4343ed040a71dd62fca Branches: phpng Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=be4878edd008a3376bfe1a60bee03cded497ad5f Log: Use stack memory here to avoid mem leak Changed paths: M ext/standard/math.c Diff: diff --git a/ext/standard/math.c b/ext/standard/math.c index c12764c..0fcbdb8 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1101,7 +1101,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len) { zend_string *res; - char *tmpbuf = NULL; + char tmpbuf[MAX_LENGTH_OF_DOUBLE]; char *s, *t; /* source, target */ char *dp; int integral; @@ -1117,10 +1117,9 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin dec = MAX(0, dec); d = _php_math_round(d, dec, PHP_ROUND_HALF_UP); - tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d); + tmplen = snprintf(tmpbuf, sizeof(tmpbuf), "%.*F", dec, d); if (tmpbuf == NULL || !isdigit((int)tmpbuf[0])) { -//??? return tmpbuf; return STR_INIT(tmpbuf, tmplen, 0); } @@ -1206,8 +1205,6 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin *t-- = '-'; } - efree(tmpbuf); - res->len = reslen; return res; }

« previous php.cvs (#77837) next »