
"Invalid Address specified to RtlFreeHeap(..)"
Hello Igor,
I am aware of this fact, I will be more specific
for you to have an exact idea, I have an ATL COM
component that receives a request, the request handler
spans a new thread which asynchrously achieves the
lengthy operation and then after completion notifies
the client app.
The Thread Function looks like this basically...
LRESULT CAE::SimulationThread(LPVOID pParam)
{
// Required for this thread to join a
// free-threaded COM appartment...
::CoInitializeEx(NULL, COINIT_MULTITHREADED);
try {
bstrXMLOut = (CSomething*)pParam->AchieveSimulation(...);
}
catch (const CAEException& aeexc) {
// Notify error...
CString strErr;
hres = aeexc.GetHRESULT();
aeexc.GetErrorMessage(strErr);
BSTR bstrErr = strErr.AllocSysString();
AtlReportError( CLSID_AE
, bstrErr
, IID_IAE
, hres);
::SysFreeString(bstrErr);
(CSomething*)pParam->Fire_OnNotifySimulationFailed(hres);
}
// Simulation completed...
if ((CSomething*)pParam->GetSimulationCancelled())
{
// Notify error...
CString strErr;
hres = CAEException::GetHRESULT(AE_SIMULATION_CANCELLEDBYUSER);
CAEException::GetErrorMessage(AE_SIMULATION_CANCELLEDBYUSER, strErr);
BSTR bstrErr = strErr.AllocSysString();
AtlReportError( CLSID_AE
, bstrErr
, IID_IAE
, hres);
::SysFreeString(bstrErr);
(CSomething*)pParam->Fire_OnNotifySimulationFailed(hres);
}
if (hres == S_OK)
{
(CSomething*)pParam->Fire_OnNotifySimulationSucceeded(bstrXMLOut);
}
::CoUninitialize();
return 0;
Quote:
}
As you can easily find there is no smart pointer in this snippet waiting for
going out
of scope after the CoUninitialize gets called. The actual MSXML smart
pointers are
declared and used from within the AchieveSimulation method call, and they
are all
assigned NULL which implicitly means calling Release right?
The funny thing is that the exception is thrown exactly in the
CoUninitialize() and not
afterwards.
Thanks for your help,
Best regards,
Giovanni
Quote:
> One possible problem is a code like this:
> int main()
> {
> CoInitialize(0);
> IXMLDocumentPtr ptr;
> ptr.CreateInstance(...);
> // ptr = 0; // uncomment to solve the problem
> CoUninitialize();
> // At this point ptr goes out of scope and calls Release on
> underlying dumb pointer,
> // but any COM calls are illegal after CoUninitialize
> }
> The same problem occurs with smart pointers as global variables.
> And of course it is always possible that you have a buffer overrun
> somewhere that corrupts the heap, or that you free some memory twice.
> --
> With best wishes,
> Igor Tandetnik
> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken
> > Hello all,
> > I developed a ATL component and I am getting
> > the exception "Invalid Address specified to RtlFreeHeap(..)"
> > error after calling ::CoUninitialize();
> > I am using MSXML with smart pointers.
> > Any hints ideas of what the problem could be?