[racket-dev] Windows ffi's 'malloc raw' can't be paired with C 'free'

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Oct 18 18:36:47 EDT 2011

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

The options for getting everything to use the same C library are not
pleasant. See


for a taste of the problem.

Posted on the dev mailing list.