- MFH zend_info_call_*() stuff, fixes coverity issue #328, noticed by tony

This commit is contained in:
Marcus Boerger 2007-04-05 19:49:42 +00:00
parent 3530b8a2c6
commit 9c5ea420ac

View File

@ -2377,19 +2377,41 @@ ZEND_API int zend_fcall_info_init(zval *callable, zend_fcall_info *fci, zend_fca
}
ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem)
{
if (fci->params) {
while (fci->param_count) {
zval_ptr_dtor(fci->params[--fci->param_count]);
}
if (free_mem) {
efree(fci->params);
fci->params = NULL;
}
}
fci->param_count = 0;
}
ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval ****params)
{
*param_count = fci->param_count;
*params = fci->params;
fci->param_count = 0;
fci->params = NULL;
}
ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval ***params)
{
zend_fcall_info_args_clear(fci, 1);
fci->param_count = param_count;
fci->params = params;
}
ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC)
{
HashPosition pos;
zval **arg, ***params;
if (fci->params) {
while (fci->param_count) {
zval_ptr_dtor(fci->params[--fci->param_count]);
}
efree(fci->params);
}
fci->params = NULL;
fci->param_count = 0;
zend_fcall_info_args_clear(fci, !args);
if (!args) {
return SUCCESS;
@ -2403,7 +2425,6 @@ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC)
fci->params = params = (zval***)safe_emalloc(sizeof(zval**), fci->param_count, 0);
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **) &arg, &pos) == SUCCESS) {
*params++ = arg;
(*arg)->refcount++;
@ -2420,8 +2441,7 @@ ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *f
fci->retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
if (args) {
org_params = fci->params;
org_count = fci->param_count;
zend_fcall_info_args_save(fci, &org_count, &org_params);
zend_fcall_info_args(fci, args TSRMLS_CC);
}
result = zend_call_function(fci, fcc TSRMLS_CC);
@ -2430,9 +2450,7 @@ ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *f
zval_ptr_dtor(&retval);
}
if (args) {
zend_fcall_info_args(fci, NULL TSRMLS_CC);
fci->params = org_params;
fci->param_count = org_count;
zend_fcall_info_args_restore(fci, org_count, org_params);
}
return result;
}