Invalid Address - RtlSizeHeap caused by function 
Author Message
 Invalid Address - RtlSizeHeap caused by function

I've got the function below which shows the Data Link dialog box in an
MMC snapin.  Everything works
fine.  However in debug mode, when the function returns, we always get
the error:

Invalid Address specified to RtlSizeHeap( 00080000, 000E0574 )

in the VC6.0 debug window. A dialog which also says

User Breakpoint called from code at 0x77f7f570.  Also appears.  We
originally had WCHAR buffers, but
thought that changing these to CComBSTR would automatically release
any memory within the buffers.

Code follows below:

CComBSTR GetDataSource(LPOLESTR lpbstrConn)
{

    CComBSTR bstr;

    IUnknown *     pUnkDataSource = NULL;
    IDataInitialize *pIDataInitialize = NULL;
    IDBPromptInitialize *     pIDBPromptInitialize = NULL;

    CoCreateInstance(     CLSID_DataLinks,
                   NULL,
                   CLSCTX_INPROC_SERVER,
                   IID_IDataInitialize,
                   (void**)&pIDataInitialize
              );    
    try
    {
         pIDataInitialize->GetDataSource(     NULL,
                                  CLSCTX_INPROC_SERVER,
                                  lpbstrConn,
                                  IID_IUnknown,
                                  (IUnknown**)&pUnkDataSource
                             );
    }
    catch(...)
    {
    }
    CoCreateInstance(     CLSID_DataLinks,                    
                             NULL,                                  
                             CLSCTX_INPROC_SERVER,              
                             IID_IDBPromptInitialize,          
                             (void**)&pIDBPromptInitialize    
                             );

    pIDBPromptInitialize->PromptDataSource(
                             NULL,                                  
                             GetDesktopWindow(),                    
                             DBPROMPTOPTIONS_PROPERTYSHEET,    
                             0,
                             NULL,                                  
                             NULL,                                  
                             IID_IUnknown,                          
                             (IUnknown**)&pUnkDataSource          
                             );

    pIDataInitialize->GetInitializationString(pUnkDataSource,false,
&bstr);

    if (pIDBPromptInitialize)
         pIDBPromptInitialize->Release();
    if (pIDataInitialize)
         pIDataInitialize->Release();
    if (pUnkDataSource)
         pUnkDataSource->Release();

    return _T("");

Quote:
};



Mon, 11 Oct 2004 00:13:54 GMT  
 Invalid Address - RtlSizeHeap caused by function
LPOLESTR and BSTR are not the same. Even though they are typedef'ed in
the same way, the memory for them is allocated differently. A string
returned by IDataInitialize::GetInitializationString is supposed to be
freed with CoTaskMemFree, but CComBSTR uses SysFreeString. You cannot
use CComBSTR here.
--
With best wishes,
    Igor Tandetnik

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


Quote:
> I've got the function below which shows the Data Link dialog box in an
> MMC snapin.  Everything works
> fine.  However in debug mode, when the function returns, we always get
> the error:

> Invalid Address specified to RtlSizeHeap( 00080000, 000E0574 )

> in the VC6.0 debug window. A dialog which also says

> User Breakpoint called from code at 0x77f7f570.  Also appears.  We
> originally had WCHAR buffers, but
> thought that changing these to CComBSTR would automatically release
> any memory within the buffers.

> Code follows below:

> CComBSTR GetDataSource(LPOLESTR lpbstrConn)
> {

>     CComBSTR bstr;

>     IUnknown *     pUnkDataSource = NULL;
>     IDataInitialize *pIDataInitialize = NULL;
>     IDBPromptInitialize *     pIDBPromptInitialize = NULL;

>     CoCreateInstance(     CLSID_DataLinks,
>                    NULL,
>                    CLSCTX_INPROC_SERVER,
>                    IID_IDataInitialize,
>                    (void**)&pIDataInitialize
>               );
>     try
>     {
>          pIDataInitialize->GetDataSource(     NULL,
>                                   CLSCTX_INPROC_SERVER,
>                                   lpbstrConn,
>                                   IID_IUnknown,
>                                   (IUnknown**)&pUnkDataSource
>                              );
>     }
>     catch(...)
>     {
>     }
>     CoCreateInstance(     CLSID_DataLinks,
>                              NULL,
>                              CLSCTX_INPROC_SERVER,
>                              IID_IDBPromptInitialize,
>                              (void**)&pIDBPromptInitialize
>                              );

>     pIDBPromptInitialize->PromptDataSource(
>                              NULL,
>                              GetDesktopWindow(),
>                              DBPROMPTOPTIONS_PROPERTYSHEET,
>                              0,
>                              NULL,
>                              NULL,
>                              IID_IUnknown,
>                              (IUnknown**)&pUnkDataSource
>                              );

>     pIDataInitialize->GetInitializationString(pUnkDataSource,false,
> &bstr);

>     if (pIDBPromptInitialize)
>          pIDBPromptInitialize->Release();
>     if (pIDataInitialize)
>          pIDataInitialize->Release();
>     if (pUnkDataSource)
>          pUnkDataSource->Release();

>     return _T("");
> };



Mon, 11 Oct 2004 00:32:59 GMT  
 Invalid Address - RtlSizeHeap caused by function
Thanks, I'll give that a try and see how it goes.

Oscar

Quote:

> LPOLESTR and BSTR are not the same. Even though they are typedef'ed in
> the same way, the memory for them is allocated differently. A string
> returned by IDataInitialize::GetInitializationString is supposed to be
> freed with CoTaskMemFree, but CComBSTR uses SysFreeString. You cannot
> use CComBSTR here.
> --
> With best wishes,
>     Igor Tandetnik

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



> > I've got the function below which shows the Data Link dialog box in an
> > MMC snapin.  Everything works
> > fine.  However in debug mode, when the function returns, we always get
> > the error:

> > Invalid Address specified to RtlSizeHeap( 00080000, 000E0574 )

> > in the VC6.0 debug window. A dialog which also says

> > User Breakpoint called from code at 0x77f7f570.  Also appears.  We
> > originally had WCHAR buffers, but
> > thought that changing these to CComBSTR would automatically release
> > any memory within the buffers.

> > Code follows below:

> > CComBSTR GetDataSource(LPOLESTR lpbstrConn)
> > {

> >     CComBSTR bstr;

> >     IUnknown *     pUnkDataSource = NULL;
> >     IDataInitialize *pIDataInitialize = NULL;
> >     IDBPromptInitialize *     pIDBPromptInitialize = NULL;

> >     CoCreateInstance(     CLSID_DataLinks,
> >                    NULL,
> >                    CLSCTX_INPROC_SERVER,
> >                    IID_IDataInitialize,
> >                    (void**)&pIDataInitialize
> >               );
> >     try
> >     {
> >          pIDataInitialize->GetDataSource(     NULL,
> >                                   CLSCTX_INPROC_SERVER,
> >                                   lpbstrConn,
> >                                   IID_IUnknown,
> >                                   (IUnknown**)&pUnkDataSource
> >                              );
> >     }
> >     catch(...)
> >     {
> >     }
> >     CoCreateInstance(     CLSID_DataLinks,
> >                              NULL,
> >                              CLSCTX_INPROC_SERVER,
> >                              IID_IDBPromptInitialize,
> >                              (void**)&pIDBPromptInitialize
> >                              );

> >     pIDBPromptInitialize->PromptDataSource(
> >                              NULL,
> >                              GetDesktopWindow(),
> >                              DBPROMPTOPTIONS_PROPERTYSHEET,
> >                              0,
> >                              NULL,
> >                              NULL,
> >                              IID_IUnknown,
> >                              (IUnknown**)&pUnkDataSource
> >                              );

> >     pIDataInitialize->GetInitializationString(pUnkDataSource,false,
> > &bstr);

> >     if (pIDBPromptInitialize)
> >          pIDBPromptInitialize->Release();
> >     if (pIDataInitialize)
> >          pIDataInitialize->Release();
> >     if (pUnkDataSource)
> >          pUnkDataSource->Release();

> >     return _T("");
> > };



Tue, 12 Oct 2004 00:26:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Invalid Address - RtlSizeHeap caused by function

2. Incomplete import address table causes jump to invalid address

3. Incomplete import address table causes jump to invalid address

4. caused an invalid page fault in module ...

5. MSDEV caused an invalid page fault in Module SSSCC.DLL After Install SP2

6. CONNECT caused an invalid page fault in module KERNEL32.DLL at 017f:bff7b9f2

7. MSDEV causing invalid page fault: HELP!

8. MSDEV causing invalid page fault: HELP!

9. MSDEV.EXE caused an invalid page fault in module SSSCC.DLL

10. RasHangUp() -> RNAAPP causing invalid page fault

11. NEED HELP: Thread Termination causes invalid page fault in Release built only

12. 3rd party implicit (load-time) dll when exitting app causes invalid page fault

 

 
Powered by phpBB® Forum Software