From: Dmitry Stogov Date: Wed, 5 Mar 2014 07:10:52 +0000 (+0400) Subject: Arguments taken by internal functions using zend_parse_parameters() with "+" and... X-Git-Tag: POST_PHPNG_MERGE~412^2~422 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=040dea8b82a00083b3975351271f34f3775d9a60;p=php Arguments taken by internal functions using zend_parse_parameters() with "+" and "*" specifications must not be deallocated anymore. --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 3e532418fb..7aacad1297 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -920,22 +920,11 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, type_spec++; if (num_varargs > 0) { - int iv = 0; - zval *p = (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count - i)); - *n_varargs = num_varargs; - - /* allocate space for array and store args */ - *varargs = (zval*)safe_emalloc(num_varargs, sizeof(zval), 0); - while (num_varargs-- > 0) { - ZVAL_COPY_VALUE(&(*varargs)[iv], p); - iv++; - p++; - } - + *varargs = (zend_vm_stack_top(TSRMLS_C) - 1 - (arg_count - i)); /* adjust how many args we have left and restart loop */ - num_args = num_args + 1 - iv; - i += iv; + num_args += 1 - num_varargs; + i += num_varargs; continue; } else { *varargs = NULL; diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 3c74ff75ba..c236f0d765 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1908,10 +1908,6 @@ ZEND_METHOD(reflection_function, invoke) result = zend_call_function(&fci, &fcc TSRMLS_CC); - if (num_args) { - efree(params); - } - if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invocation of function %s() failed", fptr->common.function_name->val); @@ -2854,7 +2850,6 @@ ZEND_METHOD(reflection_method, invoke) obj_ce = mptr->common.scope; } else { if (Z_TYPE(params[0]) != IS_OBJECT) { - efree(params); _DO_THROW("Non-object passed to Invoke()"); /* Returns from this function */ } @@ -2862,9 +2857,6 @@ ZEND_METHOD(reflection_method, invoke) obj_ce = Z_OBJCE(params[0]); if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) { - if (params) { - efree(params); - } _DO_THROW("Given object is not an instance of the class this method was declared in"); /* Returns from this function */ } @@ -2890,10 +2882,6 @@ ZEND_METHOD(reflection_method, invoke) result = zend_call_function(&fci, &fcc TSRMLS_CC); - if (params) { - efree(params); - } - if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invocation of method %s::%s() failed", mptr->common.scope->name->val, mptr->common.function_name->val); @@ -4207,9 +4195,6 @@ ZEND_METHOD(reflection_class, newInstance) } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) { - if (params) { - efree(params); - } zval_dtor(return_value); RETURN_FALSE; } @@ -4231,9 +4216,6 @@ ZEND_METHOD(reflection_class, newInstance) ZVAL_COPY_VALUE(&fcc.object, return_value); if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - if (params) { - efree(params); - } if (!ZVAL_IS_UNDEF(&retval)) { zval_ptr_dtor(&retval); } @@ -4244,9 +4226,6 @@ ZEND_METHOD(reflection_class, newInstance) if (!ZVAL_IS_UNDEF(&retval)) { zval_ptr_dtor(&retval); } - if (params) { - efree(params); - } } else if (ZEND_NUM_ARGS()) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name->val); } diff --git a/ext/session/session.c b/ext/session/session.c index e16b79f585..9f56c3a301 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1875,7 +1875,6 @@ static PHP_FUNCTION(session_set_save_handler) /* at this point argc can only be 6 or 7 */ for (i = 0; i < argc; i++) { if (!zend_is_callable(*args[i], 0, &name TSRMLS_CC)) { - efree(args); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument %d is not a valid callback", i+1); efree(name); RETURN_FALSE; @@ -1895,7 +1894,6 @@ static PHP_FUNCTION(session_set_save_handler) PS(mod_user_names).names[i] = *args[i]; } - efree(args); RETURN_TRUE; } /* }}} */ diff --git a/ext/standard/array.c b/ext/standard/array.c index 659ab25a86..0535e57849 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -969,10 +969,6 @@ PHP_FUNCTION(min) RETVAL_ZVAL_FAST(min); } - - if (args) { - efree(args); - } } /* }}} */ @@ -1020,10 +1016,6 @@ PHP_FUNCTION(max) RETVAL_ZVAL_FAST(max); } - - if (args) { - efree(args); - } } /* }}} */ @@ -1474,10 +1466,6 @@ PHP_FUNCTION(compact) for (i=0; i= argc) { efree(result); - efree(args); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments"); return NULL; } @@ -649,8 +643,6 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC) } } - efree(args); - /* possibly, we have to make sure we have room for the terminating null? */ result->val[outpos]=0; result->len = outpos; diff --git a/ext/standard/pack.c b/ext/standard/pack.c index d4208e7ac6..3fffb046d6 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -174,7 +174,6 @@ PHP_FUNCTION(pack) case 'h': case 'H': if (currentarg >= num_args) { - efree(argv); efree(formatcodes); efree(formatargs); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: not enough arguments", code); @@ -220,7 +219,6 @@ PHP_FUNCTION(pack) currentarg += arg; if (currentarg > num_args) { - efree(argv); efree(formatcodes); efree(formatargs); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: too few arguments", code); @@ -229,7 +227,6 @@ PHP_FUNCTION(pack) break; default: - efree(argv); efree(formatcodes); efree(formatargs); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: unknown format code", code); @@ -485,7 +482,6 @@ PHP_FUNCTION(pack) } } - efree(argv); efree(formatcodes); efree(formatargs); output[outputpos] = '\0'; diff --git a/ext/standard/string.c b/ext/standard/string.c index 66e6a4c8a1..65522cc36f 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4333,9 +4333,6 @@ PHP_FUNCTION(setlocale) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid locale category name %s, must be one of LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME", category); zval_dtor(&tmp); - if (args) { - efree(args); - } RETURN_FALSE; } zval_dtor(&tmp); @@ -4385,9 +4382,6 @@ PHP_FUNCTION(setlocale) } zval_dtor(&tmp); - if (args) { - efree(args); - } RETURN_STRING(retval); } zval_dtor(&tmp); @@ -4400,9 +4394,6 @@ PHP_FUNCTION(setlocale) } #endif - if (args) { - efree(args); - } RETURN_FALSE; } /* }}} */ @@ -5272,10 +5263,6 @@ PHP_FUNCTION(sscanf) result = php_sscanf_internal(str, format, num_args, args, 0, return_value TSRMLS_CC); - if (args) { - efree(args); - } - if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { WRONG_PARAM_COUNT; } diff --git a/ext/standard/var.c b/ext/standard/var.c index 219cd6badb..20bbf545d5 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -187,7 +187,6 @@ PHP_FUNCTION(var_dump) for (i = 0; i < argc; i++) { php_var_dump(&args[i], 1 TSRMLS_CC); } - efree(args); } /* }}} */ @@ -338,7 +337,6 @@ PHP_FUNCTION(debug_zval_dump) for (i = 0; i < argc; i++) { php_debug_zval_dump(&args[i], 1 TSRMLS_CC); } - efree(args); } /* }}} */