BUG: Incorrect Code Generated by the Cluster Resource Type Wizard

ID: Q219415


The information in this article applies to:


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 this to be a bug in the Microsoft products listed at the beginning of this article.

Additional query words:


Keywords          : kbClustServ100bug kbVC500bug kbVC600bug 
Version           : winnt:5.0,5.0sp1,5.0sp2,5.0sp3,6.0
Platform          : winnt 
Issue type        : kbbug 

Last Reviewed: June 16, 1999