com php-src: Fixed memory leak in getimagesize: ext/standard/image.c
| From: | Dmitry Stogov | Date: | Thu, 06 Mar 2014 10:30:32 +0000 |
| Subject: | com php-src: Fixed memory leak in getimagesize: ext/standard/image.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77729@lists.php.net to get a copy of this message | ||
Commit: e4f5b9ac381f0751ce769050ebf670f1988fd059
Author: Xinchen Hui <laruence@gmail.com> Thu, 6 Mar 2014 18:30:32 +0800
Parents: b2124612976bf4f3a56f43f6e78f7d11a3a28d3e
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e4f5b9ac381f0751ce769050ebf670f1988fd059
Log:
Fixed memory leak in getimagesize
Changed paths:
M ext/standard/image.c
Diff:
diff --git a/ext/standard/image.c b/ext/standard/image.c
index ce48b96..137f91b 100644
--- a/ext/standard/image.c
+++ b/ext/standard/image.c
@@ -1289,9 +1289,8 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
}
/* }}} */
-static void php_getimagesize_from_stream(php_stream *stream, zval **info,
INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
+static void php_getimagesize_from_stream(php_stream *stream, zval *info,
INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
{
- char *temp;
int itype = 0;
struct gfxinfo *result = NULL;
@@ -1306,7 +1305,7 @@ static void php_getimagesize_from_stream(php_stream *stream, zval **info,
INTERN
break;
case IMAGE_FILETYPE_JPEG:
if (info) {
- result = php_handle_jpeg(stream, *info TSRMLS_CC);
+ result = php_handle_jpeg(stream, info TSRMLS_CC);
} else {
result = php_handle_jpeg(stream, NULL TSRMLS_CC);
}
@@ -1360,11 +1359,12 @@ static void php_getimagesize_from_stream(php_stream *stream, zval **info,
INTERN
}
if (result) {
+ char temp[MAX_LENGTH_OF_LONG * 2 + sizeof("width=\"\"
height=\"\"")];
array_init(return_value);
add_index_long(return_value, 0, result->width);
add_index_long(return_value, 1, result->height);
add_index_long(return_value, 2, itype);
- spprintf(&temp, 0, "width=\"%d\" height=\"%d\"",
result->width, result->height);
+ snprintf(temp, sizeof(temp), "width=\"%d\" height=\"%d\"",
result->width, result->height);
add_index_string(return_value, 3, temp, 0);
if (result->bits != 0) {
@@ -1385,22 +1385,22 @@ static void php_getimagesize_from_stream(php_stream *stream, zval **info,
INTERN
#define FROM_PATH 1
static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) { /* {{{ */
- zval **info = NULL;
+ zval *info = NULL;
php_stream *stream = NULL;
char *input;
int input_len;
const int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &input, &input_len, &info)
== FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "s|z", &input, &input_len, &info)
== FAILURE) {
return;
}
if (argc == 2) {
- zval_dtor(*info);
- array_init(*info);
+ info = Z_REFVAL_P(info);
+ zval_dtor(info);
+ array_init(info);
}
-
if (mode == FROM_PATH) {
stream = php_stream_open_wrapper(input, "rb",
STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH, NULL);
} else {