[Mono-devel-list] Re: [PATCH] Improper free of return-value string pointers from unmanagedcalls

Steven Brown swbrown at ucsd.edu
Fri Jun 11 02:35:51 EDT 2004

Chris Day wrote:

> Just as an FYI, Microsoft recommends [1] that any return or out
> parameters for strings (char*, wchar_t*, etc) use an IntPtr then use
> Marshal.PtrToString* [2] to copy it into managed land.  If the function
> allocates the string it is then up to you to import a free() function
> which you can call with the IntPtr to deallocate the string.
> Chris
> [1]
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=ON3LnWFHBHA.1868
> %40tkmsftngp03
> [2]
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/h
> tml/frlrfsystemruntimeinteropservicesmarshalclassptrtostringautotopic1.a
> sp 

In [1], he's talking about out parameters, not return parameters 
(although he calls them return parameters).  It's a different beast, as 
the guy's code is written to expect an immutable string to be modified.

More information about the Mono-devel-list mailing list