[Mono-devel-list] Re: [PATCH] Improper free of return-value string pointers from unmanaged calls
Steven Brown
swbrown at ucsd.edu
Fri Jun 11 20:55:24 EDT 2004
Jonathan Pryor wrote:
> On Fri, 2004-06-11 at 01:32, Steven Brown wrote:
[...]
>>MEMEAT_API char *foo(void)
>>{
>> static char *str = "Hello there";
>> static int i = 0;
>> char *newstr = (char *) malloc(strlen(str) + 1);
>> strcpy(newstr, str);
>> printf("%i: %s\n", i++, newstr);
>> return newstr;
>>}
>
>
> This code is wrong for .NET anyway. Malloc/free isn't used under .NET;
> CoTaskMemAlloc()/CoTaskMemFree() is.
And there's my error. I had been using malloc/strdup/etc. to test if it
leaked. I was sure I also tried CoTaskMemAlloc last night, but I must
have screwed that test up. It seems CoTaskMemFree as used by the
marshaller hadn't been causing any apparent badness or errors when
called on addresses not allocated by CoTaskMemAlloc which is why the
existing code I've been trying to get running on Mono had been working
seemingly flawlessly for years on Microsoft's .NET. I'll correct it to
use IntPtr.
I apologize for the snipe hunt.
More information about the Mono-devel-list
mailing list