BUG: Using #import May Cause Memory LeaksID: Q231872
|
When using #import to generate wrapper classes for COM objects, _com_dispatch_method(), _com_dispatch_raw_method(), _com_dispatch_propput(), _com_dispatch_raw_propput(), _com_dispatch_propget(), and _com_dispatch_raw_propget() function calls may be generated.
These functions leak memory if an exception is thrown by the COM object. Specifically, ICreateErrorInfo is not released and three BSTRs are not freed.
This is due to a bug in the internal implementation of the compiler native COM support.
A supported fix that corrects this problem is now available from Microsoft.
To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information on support costs, please go to the following address on the World Wide Web:
http://support.microsoft.com/support/supportnet/default.asp
The English version of this fix should have the following file attributes or later:
Date Time Size File Name Version# Platform
-------------------------------------------------------------------
06/04/1999 11:14PM 184KB COMSUPP.LIB N/A (x86)
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
Public Sub Leak()
End Sub
Err.Raise vbObjectError + &H200 + 5
#import "C:\LeakServer.dll" no_namespace no_dual_interfaces
_LeakTesterPtr serv;
HRESULT hr = serv.CreateInstance(__uuidof(LeakTester));
if (FAILED(hr))
{
TRACE("Create failed= %x\n", hr);
return;
}
int nResponse = AfxMessageBox ("Catch 10 _com_errors?", MB_YESNO);
while (IDYES == nResponse)
{
for (int iLoop = 0; iLoop < 10; iLoop++)
{
try
{
serv->Leak();
}
catch(_com_error &x)
{
int i = 0;
}
}
nResponse = AfxMessageBox ("Catch 10 _com_errors?", MB_YESNO);
}
struct InitCOM
{
InitCOM() { CoInitialize(NULL); }
~InitCOM() { CoUninitialize(); }
} g_Init;
Additional query words: leak _com_ptr_t _com_error native COM #import kbqfe
Keywords : kbCOMt kbLangCPP kbVC600bug kbVC600QFE kbSmartPtr
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: July 16, 1999