php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17012 releasing IDispatch interface too many times (putprop issue)
Submitted: 2002-05-05 08:38 UTC Modified: 2002-05-30 19:19 UTC
From: rybak at gorlice dot net dot pl Assigned:
Status: Closed Package: COM related
PHP Version: 4.2.0 OS: WinNT 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 50 = ?
Subscribe to this entry?

 
 [2002-05-05 08:38 UTC] rybak at gorlice dot net dot pl
hello
I wrote a script to access ADO database:
----------------------------------------------------
	$conn = new COM('ADODB.Connection');
			
	$hr = $conn->Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb',"", "", 0);

	$oCmd = new COM('ADODB.Command');
	$oCmd->ActiveConnection = $conn;
	$oCmd->CommandText = "INSERT INTO config(storage) VALUES('testowa wartosc')";
	$oCmd->CommandType = 1;

	$rs = $oCmd->Execute();
----------------------------------------------------
in line 
$oCmd->ActiveConnection = $conn;
there is created a zendval variable (result from assigning IDispatch $conn to property) but $conn is not AddRef-ed...
When this invisible variable is destroyed it calls Release on IDispatch from $conn -  But this dispatch is already 0-referenced.
I isolated the code in file COM.c in line 1142 (function do_COM_propput):
---------------------------------------------------
	if (SUCCEEDED(hr)) {
		php_variant_to_pval(var_result, return_value, codepage TSRMLS_CC);
	} else {
--------------------------------------------------
and changed to:
---------------------------------------------------
	if (SUCCEEDED(hr)) {
		if ( var_result->vt == VT_DISPATCH )
			var_result->pdispVal->lpVtbl->AddRef(var_result->pdispVal);
		php_variant_to_pval(var_result, return_value, codepage TSRMLS_CC);
	} else {
----------------------------------------------------
Is it a good solution? Or maybe I don't understand something?
Tristan Rybak

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-30 09:59 UTC] phanto@php.net
The fix would be fine but the actual question is 'shouldn't they addref it?'
afaik one should call addref each time an idispatch pointer is obtained from somewhere and as we give it away _they_ (ADODB) obtain it and should addref the pointer themselfes.
but during investigation i found some other flaws, maybe your problem is related to them.
 [2002-05-30 19:19 UTC] phanto@php.net
as you might have noticed already i haven't slept much when i read your bug report :)
the AddRef() wasn't missing on the instance that is set but on the return value.
it is fixed in cvs now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC