From: Wez Furlong Date: Sun, 9 Feb 2003 21:40:13 +0000 (+0000) Subject: Fix various little leaks and segfaults. X-Git-Tag: RELEASE_0_5~1172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03e22793ffff5bdd404b341d71222a2e2b787b01;p=php Fix various little leaks and segfaults. Fix scripts like this: $obj = new COM('Foo'); $obj2 = $obj->get_object(); $obj2->method(); // <-- would segfault here --- diff --git a/ext/rpc/com/com.c b/ext/rpc/com/com.c index 454d6dceb8..94f8b442e9 100644 --- a/ext/rpc/com/com.c +++ b/ext/rpc/com/com.c @@ -491,26 +491,18 @@ static int com_call(rpc_string method_name, void **data, zval *return_value, int DISPID dispid; DISPPARAMS dispparams; HRESULT hr; - OLECHAR *funcname; - VARIANT *variant_args, *result; + OLECHAR *funcname = NULL; + VARIANT *variant_args; + VARIANT result; int current_arg, current_variant; char *ErrString; TSRMLS_FETCH(); - funcname = php_char_to_OLECHAR(method_name.str, method_name.len, CP_ACP, FALSE); + /* if the length of the name is 0, we are dealing with a pointer to a dispid */ + assert(method_name.len == 0); + dispid = *(DISPID*)method_name.str; - if (FAILED(hr = php_COM_get_ids_of_names((comval *) *data, funcname, &dispid))) { - char *error_message; - - error_message = php_COM_error_message(hr); - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Unable to lookup %s: %s", method_name.str, error_message); - LocalFree(error_message); - efree(funcname); - - return FAILURE; - } - - variant_args = (VARIANT *) emalloc(sizeof(VARIANT) * num_args); + variant_args = num_args ? (VARIANT *) emalloc(sizeof(VARIANT) * num_args) : NULL; for (current_arg = 0; current_arg < num_args; current_arg++) { current_variant = num_args - current_arg - 1; @@ -522,10 +514,9 @@ static int com_call(rpc_string method_name, void **data, zval *return_value, int dispparams.cArgs = num_args; dispparams.cNamedArgs = 0; - result = (VARIANT *) emalloc(sizeof(VARIANT)); - VariantInit(result); + VariantInit(&result); - hr = php_COM_invoke((comval *) *data, dispid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, &dispparams, result, &ErrString); + hr = php_COM_invoke((comval *) *data, dispid, DISPATCH_METHOD|DISPATCH_PROPERTYGET, &dispparams, &result, &ErrString); for (current_arg=0;current_argRelease(C_ENUMVARIANT(obj)); } - hr = C_DISPATCH_VT(obj)->Release(C_DISPATCH(obj)); + if (C_DISPATCH(obj)) { + hr = C_DISPATCH_VT(obj)->Release(C_DISPATCH(obj)); + } efree(obj); return hr; @@ -908,15 +910,13 @@ ZEND_API int php_COM_load_typelib(ITypeLib *TypeLib, int mode) PHPAPI zval *php_COM_object_from_dispatch(IDispatch *disp) { comval *obj; - zval *zobj; TSRMLS_FETCH(); ALLOC_COM(obj); - MAKE_STD_ZVAL(zobj); php_COM_set(obj, &disp, FALSE); - ZVAL_COM(zobj, obj); - return zobj; + return rpc_object_from_data(NULL, com, obj, NULL); + } #endif diff --git a/ext/rpc/com/variant.h b/ext/rpc/com/variant.h index 2cef0bdeaa..81004855bc 100644 --- a/ext/rpc/com/variant.h +++ b/ext/rpc/com/variant.h @@ -33,20 +33,13 @@ #define ZVAL_VARIANT(z, v, cp) \ if (V_VT(v) == VT_DISPATCH) { \ - rpc_internal *intern; \ comval *obj; \ ALLOC_COM(obj); \ - Z_TYPE_P(z) = IS_OBJECT; \ - (z)->value.obj = rpc_objects_new(com_class_entry TSRMLS_CC); \ - if (GET_INTERNAL_EX(intern, (z)) != SUCCESS) { \ - /* TODO: exception */ \ - } \ php_COM_set(obj, &V_DISPATCH(v), TRUE); \ - intern->data = obj; \ + rpc_object_from_data(z, com, obj, NULL); \ } else { \ php_variant_to_zval((v), (z), cp); \ VariantClear(v); \ - efree(v); \ } #define RETVAL_VARIANT(v, cp) ZVAL_VARIANT(return_value, v, cp)