com php-src: Fixed memory leak: ext/standard/formatted_print .c
| From: | Dmitry Stogov | Date: | Thu, 06 Mar 2014 10:42:16 +0000 |
| Subject: | com php-src: Fixed memory leak: ext/standard/formatted_print .c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77719@lists.php.net to get a copy of this message | ||
Commit: 08aadb063853a31af16c4eb3ac2a7e3dab13db46
Author: Dmitry Stogov <dmitry@zend.com> Thu, 6 Mar 2014 14:42:16 +0400
Parents: 0b6af572565e12a5c94808e93e33548ec09fad69
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=08aadb063853a31af16c4eb3ac2a7e3dab13db46
Log:
Fixed memory leak
Changed paths:
M ext/standard/formatted_print.c
Diff:
diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c
index 856c94a..325b242 100644
--- a/ext/standard/formatted_print.c
+++ b/ext/standard/formatted_print.c
@@ -371,6 +371,7 @@ php_sprintf_getnumber(char *buffer, int *pos)
static zend_string *
php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
{
+ zval *newargs = NULL;
zval *args, *z_format;
int argc, size = 240, inpos = 0, outpos = 0, temppos;
int alignment, currarg, adjusting, argnum, width, precision;
@@ -390,7 +391,7 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
if (use_array) {
int i = 1;
- zval *newargs, *zv;
+ zval *zv;
zval array;
z_format = &args[format_offset];
@@ -448,6 +449,9 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
if (argnum <= 0) {
efree(result);
+ if (newargs) {
+ efree(newargs);
+ }
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument number must be greater than
zero");
return NULL;
}
@@ -488,6 +492,9 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
PRINTF_DEBUG(("sprintf: getting width\n"));
if ((width = php_sprintf_getnumber(format, &inpos)) < 0) {
efree(result);
+ if (newargs) {
+ efree(newargs);
+ }
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Width must be greater than zero and less
than %d", INT_MAX);
return NULL;
}
@@ -504,6 +511,9 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
if (isdigit((int)format[inpos])) {
if ((precision = php_sprintf_getnumber(format, &inpos)) < 0) {
efree(result);
+ if (newargs) {
+ efree(newargs);
+ }
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Precision must be greater than zero and
less than %d", INT_MAX);
return NULL;
}
@@ -523,6 +533,9 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
if (argnum >= argc) {
efree(result);
+ if (newargs) {
+ efree(newargs);
+ }
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments");
return NULL;
}
@@ -643,6 +656,10 @@ php_formatted_print(int param_count, int use_array, int format_offset
TSRMLS_DC)
}
}
+ if (newargs) {
+ efree(newargs);
+ }
+
/* possibly, we have to make sure we have room for the terminating null? */
result->val[outpos]=0;
result->len = outpos;