[Mono-dev] Embedding Mono + SWIG string return values leads to bad free
robertj at gmx.net
Wed Apr 23 08:12:59 EDT 2008
Ewen Cheslack-Postava wrote:
> This seems to work well on Linux and Mac OS X, but on Windows it
> causes an exception when the GC tries to free that same memory. I've
> verified that I do in fact get a new copy of the string out at a
> different address from the original. It looks like maybe the string
> is just being double freed. The specific error I get (only in the
> Visual Studio debugger) is:
> HEAP[x.exe]: Invalid Address specified to RtlFreeHeap( 01E00000, 00166C78 )
On Windows, the char* returned by the C# method must be freed with
GlobalFree (). You're probable using free () which is expecting
that the memory was allocated from another heap.
This is for compatibility with MS.NET.
More information about the Mono-devel-list