]> granicus.if.org Git - php/commitdiff
- MFH zend_info_call_*() stuff, fixes coverity issue #328, noticed by tony
authorMarcus Boerger <helly@php.net>
Thu, 5 Apr 2007 19:49:42 +0000 (19:49 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 5 Apr 2007 19:49:42 +0000 (19:49 +0000)
Zend/zend_API.c

index c6a3f87f17fb2f1d10d69e70e6e937b7db7825e5..1524031deede9ff5e595dff021812352ac3fc3d9 100644 (file)
@@ -2377,19 +2377,41 @@ ZEND_API int zend_fcall_info_init(zval *callable, zend_fcall_info *fci, zend_fca
 }
 
 
-ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC)
+ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem)
 {
-       HashPosition pos;
-       zval         **arg, ***params;
-
        if (fci->params) {
                while (fci->param_count) {
                        zval_ptr_dtor(fci->params[--fci->param_count]);
                }
-               efree(fci->params);
+               if (free_mem) {
+                       efree(fci->params);
+                       fci->params = NULL;
+               }
        }
-       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;
+
+       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;
 }