I currently have a heap corruption that is causing my application to crash. My application which is the COM server (C++) marshalls to a C# client application. It looks like a SysFreeString being called possibly from the C# side as part of a COM cleanup. I can't seem to pinpoint the cause but is it possible that doing a memset 0 on the C++ side on a structure that has a BSTR in it cause problems?
Is the following valid?
memset(pResult, 0, sizeof(RESULT)) where pResult is of type RESULT
typedef struct _Result
{
DWORD dwResult;
BSTR strData;
} RESULT;
STACK_TEXT from WinDbg:
00000000`77b4b518 00000000`77a7bc35 ntdll! ?? ::FNODOBFM::`string'+0xea19 00000000`77b4b520 000007fe`ffc41377 oleaut32!SysFreeString+0x53 00000000`77b4b528 000007fe`ffc46b2e oleaut32!BSTR_UserFree+0x1e 00000000`77b4b530 000007fe`fe354a1c rpcrt4!NdrUserMarshalFree+0x4c 00000000`77b4b538 000007fe`fe3566eb rpcrt4!NdrpFreeParams+0x207 00000000`77b4b540 000007fe`fe365362 rpcrt4!NdrStubCall2+0xedc 00000000`77b4b548 000007fe`fe84f16e ole32!CStdStubBuffer_Invoke+0x8b 00000000`77b4b550 000007fe`fe850ccd ole32!SyncStubInvoke+0x5d 00000000`77b4b558 000007fe`fe850c43 ole32!StubInvoke+0xdb 00000000`77b4b560 000007fe`fe70a4f0 ole32!CCtxComChnl::ContextInvoke+0x190 00000000`77b4b568 000007fe`fe8514d6 ole32!AppInvoke+0xc2 00000000`77b4b570 000007fe`fe85122b ole32!ComInvokeWithLockAndIPID+0x52b 00000000`77b4b578 000007fe`fe84fd6d ole32!ThreadInvoke+0x30d 00000000`77b4b580 000007fe`fe363254 rpcrt4!DispatchToStubInCNoAvrf+0x14 00000000`77b4b588 000007fe`fe3633b6 rpcrt4!RPC_INTERFACE::DispatchToStubWorker+0x146 00000000`77b4b590 000007fe`fe365b8b rpcrt4!RPC_INTERFACE::DispatchToStub+0x9b 00000000`77b4b598 000007fe`fe365acb rpcrt4!RPC_INTERFACE::DispatchToStubWithObject+0x5b 00000000`77b4b5a0 000007fe`fe365a62 rpcrt4!LRPC_SCALL::DispatchRequest+0x422 00000000`77b4b5a8 000007fe`fe36375d rpcrt4!LRPC_SCALL::HandleRequest+0x20d 00000000`77b4b5b0 000007fe`fe3809ff rpcrt4!LRPC_ADDRESS::ProcessIO+0x3bf 00000000`77b4b5b8 000007fe`fe3805b5 rpcrt4!LrpcIoComplete+0xa5 00000000`77b4b5c0 00000000`77a2b6bb ntdll!TppAlpcpExecuteCallback+0x26b 00000000`77b4b5c8 00000000`77a2ff2f ntdll!TppWorkerThread+0x3f8 00000000`77b4b5d0 00000000`7790652d kernel32!BaseThreadInitThunk+0xd 00000000`77b4b5d8 00000000`77a3c541 ntdll!RtlUserThreadStart+0x1d