Q219415: PRB: Incorrect Code Generated by Cluster Resource Type Wizard

Article: Q219415
Product(s): Microsoft C Compiler
Version(s): 5.0,5.0sp1,5.0sp2,5.0sp3,6.0
Operating System(s): 
Keyword(s): kbClustServ100bug kbVC500bug kbVC600bug kbprb kbNoUpdate
Last Modified: 12-FEB-2002

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual C++, 32-bit Enterprise Edition, versions 5.0, 5.0sp1, 5.0sp2, 5.0sp3, 6.0 
- Microsoft Visual C++, 32-bit Professional Edition, versions 5.0, 5.0sp1, 5.0sp2, 5.0sp3, 6.0 
- Microsoft Visual C++, 32-bit Learning Edition, version 6.0 
- Microsoft Cluster Server 
-------------------------------------------------------------------------------

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 kbprb kbNoUpdate 
Technology        : kbVCsearch kbAudDeveloper kbClustServSearch kbVC500 kbVC600 kbVC32bitSearch kbVC500SP1 kbVC500SP2 kbVC500SP3 kbVC500Search
Version           : :5.0,5.0sp1,5.0sp2,5.0sp3,6.0
Issue type        : kbbug kbprb
Solution Type     : kbfix

=============================================================================