[racket-dev] Windows ffi's 'malloc raw' can't be paired with C 'free'
On Oct 18, 2011, at 3:36 PM, Matthew Flatt wrote:
> At Tue, 18 Oct 2011 15:27:28 -0700, John Clements wrote:
>> It looks like there's a problem with the ffi implementation of (malloc ...
>> 'raw) in Windows. In particular, if I call 'free()' in a C extension on a
>> block of memory that was allocated with (malloc ... 'raw), I get the Windows
>> equivalent of a core dump, with an exception code that indicates "heap
>> corruption".
>
> The problem is that Racket and the extension are linked to different C
> libraries, so you can use `malloc' from Racket only with `free' from
> Racket.
>
> The options for getting everything to use the same C library are not
> pleasant. See
>
> http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/
>
> for a taste of the problem.
>
Two small follow-ups.
1) This is only a problem under Windows, right?
2) It looks to me like there's an easy workaround in my case, which is simply to put the 'malloc' on the C side in a one-line stub function. Right?
Many thanks for the prompt response.
John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20111018/13307ca3/attachment.p7s>