FIX: COleDispatchDriver::InvokeHelperV Causes Memory Leaks

Last reviewed: September 18, 1997
Article ID: Q124066
1.50 WINDOWS kbole kbfixlist kbbuglist

The information in this article applies to:

   The Microsoft Foundation Classes (MFC), included with
     - Microsoft Visual C++ for Windows, version 1.5

SYMPTOMS

Creating a COleDispatchDriver derived class from an automation object's type library for a particular object may result in a memory leak when subsequently calling its member functions. This leak is caused by a bug in the InvokeHelperV member function of the COleDispatchDriver class used by the member functions of the derived class to call the OLE automation object's methods.

CAUSE

COleDispatchDriver::InvokeHelperV function, eventually called by all method member functions, incorrectly calculates the parameter information and will not free memory associated with BSTR (String) parameters. The error is marked below in a small segment taken from the COleDispatchDriver::InvokeHelperV function:

void COleDispatchDriver::InvokeHelperV(DISPID dwDispID, WORD wFlags,
                                       VARTYPE vtRet, void* pvRet,
                                       const BYTE FAR* pbParamInfo,
                                       va_list, argList)
{
  ...

  // cleanup any arguments that need cleanup
  if (dispparams.cArgs != 0)
  {
    VARIANTARG FAR* pArg = dispparams.rgvarg;
    // BUG: wrong start address
    // the correct line included in Visual C++ 1.51:
    // VARIANTARG FAR* pArg = dispparams.rgvarg + dispparams.cArgs - 1;

    const BYTE FAR* pb = pbParamInfo;
    while (*pb != 0)
    {
      switch ((VARTYPE)*pb)
      {
        case VT_BSTR:
          VariantClear(pArg); // BUG: wrong address gets passed since
                              // initial calculation was wrong
          break;
        ...
      }
      ++pArg;
     // BUG: wrong direction for parameters (they're in reverse order)
     // the correct line included in Visual C++ 1.51:
     // --pArg;
      ++pb;
    }
  }
  ....
}

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in the Microsoft Foundation Classes version 2.51 that was included with Microsoft Visual C++ version 1.51 for Windows.


Additional reference words: 1.50 2.50
KBCategory: kbole kbfixlist kbbuglist
KBSubCategory: MfcOLE
Keywords : kb16bitonly kbbuglist kbfixlist kbole
Technology : kbMfc
Version : 1.50
Platform : WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.