[cffi-devel] foreign-free not freeing memory not allocated by CFFI

Luís Oliveira luismbo at gmail.com
Sun May 22 21:10:31 UTC 2011


On Sat, May 21, 2011 at 1:21 AM, Luke Crook <luke at balooga.com> wrote:
> I think the problem is that CFFI does not allow memory to be freed if that
> memory has not also been allocated using CFFI.

Indeed, you shouldn't call FOREIGN-FREE on pointers to memory not
allocated by FOREIGN-ALLOC. You should be able to (defcfun free ...)
and use that.


> In my code below, a new 'sdl-version' struct is returned by
> (sdl-mixer-cffi::linked-version). The error seems to occur when I try to
> free the struct at the end of the function using foreign-free.

However, under SBCL FOREIGN-FREE is equivalent to free() -- not sure
about CCL. According to SDL_Mixer's documentation,
Mix_Linked_Version() returns a const pointer, so it seems that the bug
here is that you're trying to free() non-malloc()ed memory.

HTH.

-- 
Luís Oliveira
http://r42.eu/~luis/




More information about the cffi-devel mailing list