You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Alessandro Forghieri <Al...@think3.com> on 2000/09/27 16:54:37 UTC

Release() called on [out,retval] parameters in COM wrappers

Greetings.

I am using xerces-com from C++ (testing with the 22/09
build,VC6SP3,winNT4sp5).

There is a number of spots where I get segfaults (well, this being windows,
thy're not *real* segfaults :) ) because the wrappers call Release() on
parameters marked [out,retval]. 
For instance:

#import <xerces-com.dll>
using namespace Xerces;
[...]
  //shorn of error checking, parameter processing, etc. etc.
  IXMLDOMDocumentPtr pDoc("xerces.DOMDocument");
  pDoc->PutvalidateOnParse(true);
  if(pDoc->load(url)) {
	//OK
  } else {
	//barf
  }
  IXMLDOMElementPtr pRoot = pDoc->GetdocumentElement();
  IXMLDOMNodeListPtr pList=pRoot->GetchildNodes();
  for(int i=0; i<length; ++i) {
      // b00m
      IXMLDOMNodePtr pNode=pList->Getitem(i);
    }

this abends on the GetItem call and the debugger shows an illegal Release()
in XMLDOMNodeListImpl.cpp:

[...]
STDMETHODIMP CXMLDOMNodeList::get_item(long index, IXMLDOMNode  **pVal)
{
	ATLTRACE(_T("CXMLDOMNodeList::get_item\n"));

	if (NULL == pVal)
		return E_POINTER;

	if(*pVal) (*pVal)->Release();            <===the culprit
	*pVal = NULL;
[...]

Note that get_item is wrapped by GetItem which, in turn, is automatically
generated by  the import statement, so I cannot really say *pVal=NULL before
calling get_item. Besides, everybody COM-savy I talked to concur that
Reelase-ing is wrong in this instance (with #import and Don Box's "Essential
COM" also in agreement)

I have found similar idioms in at least the following files:

XMLDOMDocument.cpp
XMLDOMElement.cpp
XMLDOMNodeList.cpp
IXMLDOMNodeImpl.inl

(but I am not claiming coverage of the issue)

Just commenting out the incriminated statements brings xerces' behavior in
line with the
Microsoft's implementation.

Now, this was discussed on the list a while ago, & I was under the
impression that the parties involved agreed this was broken and needed some
fixing, but it appears this is not the case.

So the question is, what's the status of this? If there is no change from
the present, I will have to use MS's control, which I'd rather not do.


Cheers,
	alf