Re: Segfault from nil table access when using ffi.gc

  • From: Chris Osborne <chris.osborne@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 11 Nov 2016 22:20:25 +0000

[snip]
I suspect the following sequence of events is occurring:
1. Your local variable called `test` is garbage collected, thus
unloading `libtest.so`.
2. Your local variable called `cells` is garbage collected, thus
calling `Abc_destruct`.
3. The code for `Abc_destruct` is no longer present in memory, thus
resulting in a segfault.

This is a good suggestion, however, added an additional call to `test` at the end of the script (just a simple `print(test)` which should print something of the form: 'userdata: 0x....' still creates the segfault. The segfault itself is due to the nil table reference, if that is not there then the destructor is called fine upon the script exit (this is checked by adding a printf to `Abc_destruct`). I feel reasonably confident that this is a luajit bug, but obviously not 100% (and I would rather it just be my silly mistake!)


Other related posts: