com php-src: Fixed memory leak in ext/standard/tests/time/strpt ime_parts.php: ext/date/php_date.c

From: Date: Thu, 06 Mar 2014 10:51:20 +0000
Subject: com php-src: Fixed memory leak in ext/standard/tests/time/strpt ime_parts.php: ext/date/php_date.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-77712@lists.php.net to get a copy of this message
Commit: 9a81b6dea43be43c6062419d5bef361be511e78e Author: Xinchen Hui <laruence@gmail.com> Thu, 6 Mar 2014 18:51:20 +0800 Parents: bbacddaf9069b19e3e6c47851b05ffa649f7744b Branches: phpng Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9a81b6dea43be43c6062419d5bef361be511e78e Log: Fixed memory leak in ext/standard/tests/time/strptime_parts.php Changed paths: M ext/date/php_date.c Diff: diff --git a/ext/date/php_date.c b/ext/date/php_date.c index d3426f9..cc6bab2 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1615,7 +1615,7 @@ PHP_FUNCTION(checkdate) /* {{{ php_strftime - (gm)strftime helper */ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) { - char *format, *buf; + char *format; int format_len; long timestamp = 0; struct tm ta; @@ -1624,6 +1624,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) timelib_time *ts; timelib_tzinfo *tzi; timelib_time_offset *offset = NULL; + zend_string *buf; timestamp = (long) time(NULL); @@ -1676,10 +1677,10 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) /* VS2012 crt has a bug where strftime crash with %z and %Z format when the initial buffer is too small. See http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code */ - buf = (char *) emalloc(buf_len); - while ((real_len=strftime(buf, buf_len, format, &ta))==buf_len || real_len==0) { + buf = STR_ALLOC(buf_len, 0); + while ((real_len = strftime(buf->val, buf_len, format, &ta)) == buf_len || real_len == 0) { buf_len *= 2; - buf = (char *) erealloc(buf, buf_len); + buf = STR_REALLOC(buf, buf_len, 0); if (!--max_reallocs) { break; } @@ -1698,11 +1699,10 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) } if (real_len && real_len != buf_len) { - buf = (char *) erealloc(buf, real_len + 1); -//??? RETURN_STRINGL(buf, real_len, 0); - RETURN_STRINGL(buf, real_len); + buf = STR_REALLOC(buf, real_len, 0); + RETURN_STR(buf); } - efree(buf); + STR_FREE(buf); RETURN_FALSE; } /* }}} */

« previous php.cvs (#77712) next »