"Invalid Address specified to RtlFreeHeap(..)" 
Author Message
 "Invalid Address specified to RtlFreeHeap(..)"

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?

TIA,
Best Regards,
Giovanni



Sun, 01 May 2005 23:51:13 GMT  
 "Invalid Address specified to RtlFreeHeap(..)"
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

Quote:
}

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


Quote:
> 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?



Mon, 02 May 2005 00:33:10 GMT  
 "Invalid Address specified to RtlFreeHeap(..)"
You need to make sure one of two things: either your smart pointers are all
out of scope by the time CoUninitialize is called, or explicitly call the
Release method just before calling CoUninitialize.

What is happening is that one of your smart pointers is trying to release an
interface pointer after COM has been shut down.



Mon, 02 May 2005 00:40:57 GMT  
 "Invalid Address specified to RtlFreeHeap(..)"

Quote:
> 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.

See http://www.mvps.org/vcfaq/com/1.htm. Also, what's bstrXMLOut?
Doesn't seem to be declared anywhere. Who's allocating and freeing it?
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Mon, 02 May 2005 01:12:26 GMT  
 "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?



Mon, 02 May 2005 01:00:28 GMT  
 "Invalid Address specified to RtlFreeHeap(..)"
Hello,

I just can't figure out what is this problem due to.

I developed all MSXML source using raw COM
interface pointers and everything worked fine, but
the client application of my component was having
memory leaks, I changed the raw COM pointers
to smart pointers and this problem appeared. My
concern is that inside the CoInitialize() and
CoUninitialize() snippet there are no smart pointers
but only BSTRs.

Is there a way to find out exactly where the
"Invalid Address specified to RtlFreeHeap" exception
is being generated perhaps installing some system debug symbols.
I have W2K Professional, how can I have those
symbols installed to find out where the problem is?

TIA,
Best Regards,
Giovanni Azua


Quote:
> 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?

> TIA,
> Best Regards,
> Giovanni



Mon, 02 May 2005 18:37:20 GMT  
 "Invalid Address specified to RtlFreeHeap(..)"
Hi Giovanni,

The symbols are available at
http://www.microsoft.com/ddk/debugging/symbolpkg.asp#Windows%20symbol...
ages

Not sure if they'll help you much here, though.

Best regards,
Kim


Quote:
> Is there a way to find out exactly where the
> "Invalid Address specified to RtlFreeHeap" exception
> is being generated perhaps installing some system debug symbols.
> I have W2K Professional, how can I have those
> symbols installed to find out where the problem is?



Mon, 02 May 2005 20:43:19 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Invalid Address specified to RtlFreeHeap (Debug in Win2000 Proffesional+SP3)

2. Invalid Address specified to RtlFreeHeap

3. Invalid Address specified to RtlFreeHeap ...

4. Invalid Address specified to RtlFreeHeap( 80000, 859ce0 )

5. "typedef specifies different struct"

6. How to specify "none"?

7. Specifying "Infinity"

8. Portability (was Re: Specifying "Infinity"

9. Raising "Invalid Property Values"

10. TCP socket: "accept" failed: Invalid argument

11. Q error "invalid function declaration"

12. Invalid Address specified to RtlValidateHeap in EXE Server

 

 
Powered by phpBB® Forum Software