BUG: Incorrect Code Generated by the Cluster Resource Type Wizard (219415)



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft Cluster Server

This article was previously published under Q219415

SYMPTOMS

Code generated for the Extension .dll by the Cluster Resource Type Wizard included in the Visual C++ versions listed above may cause an access violation in Cluster Administrator if an error occurs while adding pages to a wizard.

CAUSE

An interface pointer is copied to an object member variable, but AddRef is never called on the interface. If an error occurs in the same method call, the local interface copy is released, but the member variable's copy won't be released. When the object's destructor is called, Release is invoked on the member variable's copy, which raises an access violation.

RESOLUTION

The following code excerpt shows the resolution for this issue:
STDMETHODIMP CExtObject::CreateWizardPages(
	IN IUnknown *		piData,
	IN IWCWizardCallback *	piCallback
	)
{
    ...

    try
    {
        ...
        m_piWizardCallback = piCallback;
        ...

        for ( ... )
        {
            ...
            
            if (!ppage->BInit(this))
                throw &exc;
            ...

        } // for
    } // try
    
    ...

    if (hr != NOERROR)
    {
        piCallback->Release();

        // The error is here. Because piCallback is saved in 
        // m_piWizardCallback, the CExtObject destructor  
        // tries to call the Release() method on this
        // interface pointer. Therefore, we need to set that 
        // pointer to NULL.
        // The following if-block must be added:
        if (m_piWizardCallback == piCallback)
        {
            m_piWizardCallback = NULL;
        }

        piData->Release();
        m_piData = NULL;
    } // if

    return hr;

}
				

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Modification Type:MajorLast Reviewed:12/1/2003
Keywords:kbBug kbfix kbNoUpdate kbprb KB219415