Re: SysAllocStringLen Causes Debug Assertion

From: troy anderson (tander67_at_hotmail.com)
Date: 04/07/04


Date: Wed, 7 Apr 2004 06:08:01 -0400

I do call SysFreeString; see the example in the first posting.

"Mike Markley" <mmarkley_online@microsoft.com> wrote in message
news:$eaSIZBHEHA.612@cpmsftngxa06.phx.gbl...
> Troy,
>
> You should call SysFreeString before exiting.
>
> Mike Markley
> mmarkley_nospam@microsoft.com
> --------------------
> | From: "troy anderson" <tander67@hotmail.com>
> | Subject: SysAllocStringLen Causes Debug Assertion
> | Date: Fri, 2 Apr 2004 18:25:01 -0500
> | Lines: 70
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> | Message-ID: <OsssnlQGEHA.3940@tk2msftngp13.phx.gbl>
> | Newsgroups:
>
microsoft.public.windowsce.app.development,microsoft.public.windowsce.embedd
>
ed,microsoft.public.windowsce.embedded.vc,microsoft.public.windowsce.platbui
> lder
> | NNTP-Posting-Host: 192.153.25.250
> | Path:
>
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
> phx.gbl!tk2msftngp13.phx.gbl
> | Xref: cpmsftngxa06.phx.gbl microsoft.public.windowsce.embedded:21423
> microsoft.public.windowsce.embedded.vc:31355
> microsoft.public.windowsce.platbuilder:47952
> microsoft.public.windowsce.app.development:22848
> | X-Tomcat-NG: microsoft.public.windowsce.platbuilder
> |
> | I have a simple application see below:
> |
> | "
> | int WINAPI _tWinMain( HINSTANCE hInstance,
> | HINSTANCE hPrevInstance,
> | LPTSTR lpCmdLine,
> | int nCmdShow)
> | {
> | LONG Stat=0;
> | BSTR b=SysAllocStringLen(NULL, 5);
> | if (b) {
> | SysFreeString(b);
> | b = NULL;
> | }
> |
> | return Stat;
> | }
> | "
> |
> | This application runs. However, on exit in PB environment I get a Debug
> | break with the call stack of
> | "
> | COREDLL!DebugBreak() line 102
> | COREDLL!EnterCriticalSection(CRITICAL_SECTION * 0x01f94418 struct
> | CRITICAL_SECTION gcsmcCoSetState) line 90 + 60 bytes
> | OLE32!McLock::McLock(CRITICAL_SECTION * 0x01f94418 struct
CRITICAL_SECTION
> | gcsmcCoSetState) line 145 + 9 bytes
> | OLE32!CoSetState(IUnknown * 0x00000000) line 1965
> | OLEAUT32!DllMain(void * 0x83eebab0, unsigned long 0, void * 0x00000001)
> | line 126 + 7 bytes
> | OLEAUT32!_DllMainCRTStartup(void * 0x83eebab0, unsigned long 0, void *
> | 0x00000001) line 29 + 17 bytes
> | NK!CallDLLEntry(Module * 0x83eebab0, unsigned long 0, void * 0x00000001)
> | line 1968 + 140 bytes
> | NK!DoProcessDetachAllDLLs(int 1) line 3879 + 13 bytes
> | NK!SC_ProcessDetachAllDLLs() line 3889 + 7 bytes
> | COREDLL!xxx_ProcessDetachAllDLLs() line 857
> | COREDLL!ExitThread(unsigned long 1137608218) line 231
> | 14000004()
> | COREDLL!PSLNotify(unsigned long 4, unsigned long 1137608218, unsigned
long
> | 0) line 58 + 21 bytes
> | NK!SC_ProcTerminate(void * 0x43ce861a, unsigned long 0) line 3535 + 14
> | bytes
> | CB_TEST!doexit(int 0, int 0, int 0) line 45 + 17 bytes
> | CB_TEST!exit(int 0) line 57 + 13 bytes
> | CB_TEST!WinMainCRTStartup(HINSTANCE__ * 0x43ce861a, HINSTANCE__ *
> | 0x00000000, unsigned short * 0x1409fcc0, int 5) line 36 + 9 bytes
> | COREDLL!MainThreadBaseFunc(void * 0x00060a90, unsigned long 1137608218,
> | unsigned long 0, unsigned long 336198848, unsigned long 5) line 402 +
19
> | bytes
> | "
> | I am unable to find out what CoSetState does so I assumed I needed to
call
> | CoInitializeEx() and CoUninitialize() at the start and end of WinMain().
> | This problem goes away but I see trace statements of
> |
> | "Process CB_TEST.exe loaded Module ole32.dll without freeing it before
> | process exit"
> | "Process CB_TEST.exe loaded Module oleaut32.dll without freeing it
before
> | process exit"
> |
> | After tracing through the kernel level code I found that for some reason
> | SysAllocStringLen is reloading oleaut32.dll and not releasing the
handle.
> | The reference count on oleaut32.dll module is one higher than it should
be
> | so UnDoDepends in loader.c does not release all of the dependencies.
> Anyone
> | know what I may be doing wrong?
> |
> | Thanks
> |
> |
> |
> |
>