phanto          Mon Feb 24 13:30:20 2003 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4/ext/com       COM.c com.h 
  Log:
  fix memleak and wrong refcounting
  
Index: php4/ext/com/COM.c
diff -u php4/ext/com/COM.c:1.90.2.4 php4/ext/com/COM.c:1.90.2.5
--- php4/ext/com/COM.c:1.90.2.4 Sun Feb  9 19:45:15 2003
+++ php4/ext/com/COM.c  Mon Feb 24 13:30:19 2003
@@ -18,7 +18,7 @@
    |         Wez Furlong  <[EMAIL PROTECTED]>                          |
    +----------------------------------------------------------------------+
  */
-/* $Id: COM.c,v 1.90.2.4 2003/02/10 00:45:15 phanto Exp $ */
+/* $Id: COM.c,v 1.90.2.5 2003/02/24 18:30:19 phanto Exp $ */
 /*
  * This module implements support for COM components that support the IDispatch
  * interface.  Both local (COM) and remote (DCOM) components can be accessed.
@@ -896,7 +896,7 @@
                efree(funcname);
                for (current_arg=0;current_arg<arg_count;current_arg++) {
                        /* don't release IDispatch pointers as they are used 
afterwards */
-                       if (V_VT(&variant_args[current_arg]) != VT_DISPATCH) {
+                       if (V_VT(&(variant_args[current_arg])) != VT_DISPATCH) {
                                /* @todo review this: what happens to an array of 
IDispatchs or a VARIANT->IDispatch */
                                VariantClear(&variant_args[current_arg]);
                        }
@@ -1789,7 +1789,6 @@
        zend_overloaded_element *overloaded_property;
        zend_llist_element *element;
        pval retval;
-       pval *return_value = &retval;
        pval **comval_handle;
        pval *object = property_reference->object;
        int type;
@@ -1835,18 +1834,18 @@
                                FREE_VARIANT(var_result);
 
                                if (obj != obj_prop) {
-                                       FREE_COM(obj_prop);
+                                       efree(obj_prop);
 
                                        retval = *object;
-                                       ZVAL_ADDREF(return_value);
+                                       zval_copy_ctor(&retval);
                                } else {
-                                       RETVAL_COM(obj);
+                                       ZVAL_COM(&retval, obj);
                                }
 
                                return retval;
                }
 
-               pval_destructor(&overloaded_property->element);
+               zval_dtor(&overloaded_property->element);
 
                if (V_VT(var_result) == VT_DISPATCH) {
                        if (V_DISPATCH(var_result) == NULL) {
@@ -1860,7 +1859,7 @@
                        php_COM_set(obj, &V_DISPATCH(var_result), TRUE TSRMLS_CC);
                        VariantInit(var_result);        // to protect C_DISPATCH(obj) 
from being freed when var_result is destructed
                } else {
-                       php_variant_to_pval(var_result, return_value, codepage 
TSRMLS_CC);
+                       php_variant_to_pval(var_result, &retval, codepage TSRMLS_CC);
 
                        FREE_COM(obj_prop);
                        obj_prop = NULL;
@@ -1868,7 +1867,7 @@
        }
 
        if (obj_prop != NULL) {
-               RETVAL_COM(obj);
+               ZVAL_COM(&retval, obj);
        }
 
 
@@ -1944,7 +1943,7 @@
                }
 
                VariantInit(var_result);        // to protect C_DISPATCH(obj) from 
being freed when var_result is destructed
-               pval_destructor(&overloaded_property->element);
+               zval_dtor(&overloaded_property->element);
        }
        FREE_VARIANT(var_result);
 
@@ -1952,7 +1951,7 @@
        do_COM_propput(NULL, obj, &overloaded_property->element, value TSRMLS_CC);
        FREE_COM(obj_prop);
 
-       pval_destructor(&overloaded_property->element);
+       zval_dtor(&overloaded_property->element);
 
        return SUCCESS;
 }
@@ -1984,9 +1983,14 @@
                && !strcmp(Z_STRVAL(function_name->element), "com")) {
                /* constructor */
                PHP_FN(com_load)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               /* free instance created by 'new' */
+               zval_dtor(object);
+
+               /* and override it with the instance created by 'com_load()' */
                *object = *return_value;
-               pval_copy_constructor(object);
-               pval_destructor(&function_name->element);
+               INIT_ZVAL(*return_value);
+
+               zval_dtor(&function_name->element);
                return;
        }
 
@@ -1994,8 +1998,8 @@
        property = php_COM_get_property_handler(property_reference);
 
        if (Z_TYPE(property) != IS_OBJECT) {
-               pval_destructor(&property);
-               pval_destructor(&function_name->element);
+               zval_dtor(&property);
+               zval_dtor(&function_name->element);
 
                /* error message - function call on a non-object */
                return;
@@ -2005,8 +2009,8 @@
        obj = (comval *)zend_list_find(Z_LVAL_PP(handle), &type);
 
        if (!obj || (type != IS_COM)) {
-               pval_destructor(&property);
-               pval_destructor(&function_name->element);
+               zval_dtor(&property);
+               zval_dtor(&function_name->element);
 
                return;
        }
@@ -2024,7 +2028,7 @@
 
                ALLOC_VARIANT(var_result);
 
-               arguments = (pval **) emalloc(sizeof(pval *)*arg_count);
+               arguments = (zval **) emalloc(sizeof(zval *)*arg_count);
                zend_get_parameters_array(ht, arg_count, arguments);
 
                if (do_COM_invoke(obj , DISPATCH_METHOD|DISPATCH_PROPERTYGET, 
&function_name->element, var_result, arguments, arg_count TSRMLS_CC) == SUCCESS) {
@@ -2036,13 +2040,8 @@
                efree(arguments);
        }
 
-       if (zend_llist_count(property_reference->elements_list) > 1) {
-               /* destruct temporary object */
-               zend_list_delete(Z_LVAL_PP(handle));
-               pval_destructor(&property);
-       }
-       
-       pval_destructor(&function_name->element);
+       zval_dtor(&property);
+       zval_dtor(&function_name->element);
 }
 
 
Index: php4/ext/com/com.h
diff -u php4/ext/com/com.h:1.13.4.1 php4/ext/com/com.h:1.13.4.2
--- php4/ext/com/com.h:1.13.4.1 Tue Jan 28 19:10:00 2003
+++ php4/ext/com/com.h  Mon Feb 24 13:30:20 2003
@@ -51,8 +51,7 @@
 #define RETURN_COM(o)  RETVAL_COM(o)                                                  
                                         \
                                                return;
 
-#define ALLOC_COM(z)   (z) = (comval *) ecalloc(1, sizeof(comval));                   
                 \
-                                               C_REFCOUNT(z) = 0;
+#define ALLOC_COM(z)   (z) = (comval *) ecalloc(1, sizeof(comval));
 
 #define FREE_COM(z)            php_COM_destruct(z TSRMLS_CC);
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to