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

Luke Crook luke at balooga.com
Sat May 21 00:21:30 UTC 2011


I received a report of an error when a function is called from
lispbuilder-sdl-mixer on the Mac in both SBCL and CCL.

http://pastebin.com/NmLX1Hgg

I think the problem is that CFFI does not allow memory to be freed if that
memory has not also been allocated using CFFI.

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.

(defun linked-version ()
    "Returns the version number of the SDL_mixer dynamic library in use as
#\(`MAJOR` `MINOR` `PATCH`\)."
  (let ((sdl-version (sdl-mixer-cffi::linked-version))
(version nil))
    (cffi:with-foreign-slots ((sdl-cffi::major sdl-cffi::minor
sdl-cffi::patch) sdl-version sdl-cffi::sdl-version)
      (setf version (vector sdl-cffi::major sdl-cffi::minor
sdl-cffi::patch)))
    (cffi:foreign-free sdl-version)
    version))

Can I get around this somehow?

-Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20110520/6decf505/attachment.html>


More information about the cffi-devel mailing list