Re: Segfault when using ffi in a loop/stderr

  • From: Chris <chris@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sun, 30 Nov 2014 19:41:48 -0500

On 11/30/2014 07:33 PM, Yichun Zhang (agentzh) wrote:
You need to anchor the "l" variable's value (returned by ffi.load) in
your Lua module test2.lua somehow. Right now it is not anchored and
can get GC'd prematurely. Valgrind reports the error


Thanks! That makes sense now that I think about it. Also sticking the 'l' variable inside "lib" seems to work as well to keep it alive.

Thanks for the tip on the collectgarbage hook, that will come in handy.

--
Chris
http://luadev.com

Other related posts: