<div class="gmail_quote">On Sun, May 22, 2011 at 2:10 PM, Luís Oliveira <span dir="ltr"><<a href="mailto:luismbo@gmail.com">luismbo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Sat, May 21, 2011 at 1:21 AM, Luke Crook <<a href="mailto:luke@balooga.com">luke@balooga.com</a>> wrote:<br>
> I think the problem is that CFFI does not allow memory to be freed if that<br>
> memory has not also been allocated using CFFI.<br>
<br>
</div>Indeed, you shouldn't call FOREIGN-FREE on pointers to memory not<br>
allocated by FOREIGN-ALLOC. You should be able to (defcfun free ...)<br>
and use that.<br>
<div class="im"><br>
<br>
> In my code below, a new 'sdl-version' struct is returned by<br>
> (sdl-mixer-cffi::linked-version). The error seems to occur when I try to<br>
> free the struct at the end of the function using foreign-free.<br>
<br>
</div>However, under SBCL FOREIGN-FREE is equivalent to free() -- not sure<br>
about CCL. According to SDL_Mixer's documentation,<br>
Mix_Linked_Version() returns a const pointer, so it seems that the bug<br>
here is that you're trying to free() non-malloc()ed memory.<br><br></blockquote><div><br></div><div>Thank you for pointing that out. I will fix that bug in my code.</div><div><br></div><span class="Apple-style-span" style="font-family: sans-serif; font-size: 12px; "><div class="parity1" style="background-color: rgb(246, 246, 240); font-family: monospace; ">
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "> /* rcg06192001 get linked library's version. */
</pre></div><div class="parity0" style="font-family: monospace; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a class="linenr" href="http://hg.libsdl.org/SDL_mixer/file/4b699c9a269d/mixer.c#l139" id="l139" style="color: rgb(153, 153, 153); text-decoration: none; ">   139</a> const SDL_version *Mix_Linked_Version(void)
</pre></div><div class="parity1" style="background-color: rgb(246, 246, 240); font-family: monospace; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a class="linenr" href="http://hg.libsdl.org/SDL_mixer/file/4b699c9a269d/mixer.c#l140" id="l140" style="color: rgb(153, 153, 153); text-decoration: none; ">   140</a> {
</pre></div><div class="parity0" style="font-family: monospace; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a class="linenr" href="http://hg.libsdl.org/SDL_mixer/file/4b699c9a269d/mixer.c#l141" id="l141" style="color: rgb(153, 153, 153); text-decoration: none; ">   141</a>      static SDL_version linked_version;
</pre></div><div class="parity1" style="background-color: rgb(246, 246, 240); font-family: monospace; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a class="linenr" href="http://hg.libsdl.org/SDL_mixer/file/4b699c9a269d/mixer.c#l142" id="l142" style="color: rgb(153, 153, 153); text-decoration: none; ">   142</a>        SDL_MIXER_VERSION(&linked_version);
</pre></div><div class="parity0" style="background-color: rgb(237, 236, 230); font-family: monospace; "><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a class="linenr" href="http://hg.libsdl.org/SDL_mixer/file/4b699c9a269d/mixer.c#l143" id="l143" style="color: rgb(153, 153, 153); text-decoration: none; ">   143</a>        return(&linked_version); </pre>
</div></span><div><span class="Apple-style-span" style="font-family: monospace; font-size: 12px; white-space: pre; "><a class="linenr" href="http://hg.libsdl.org/SDL_mixer/file/4b699c9a269d/mixer.c#l144" id="l144" style="color: rgb(153, 153, 153); text-decoration: none; ">   144</a> }</span></div>
<div><br></div><div><span class="Apple-style-span" style="font-family: monospace; font-size: 12px; white-space: pre; "></span>FYI; Lispworks doesn't complain about freeing the pointer.</div><div><br></div><div>-Luke</div>
</div>