Re: Random crashes with ABC enabled

  • From: demetri <demetri.spanos@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 27 Mar 2014 11:55:56 -0700

>
>
> Could you confirm that by "unanchored FFI cdata" you mean native
> arrays which are deallocated randomly by non-Lua part?
>

Not to put words in anyone's mouth, but this usually refers to the
relatively
common bug of passing ffi.new'd objects outside the scope in which they're
created without an anchoring table (which means that they can be GC'd
unexpectedly). Compare these first two cases against the third case to
follow:

-- Case 1 (anchored by table outside constructor function)
local anchoring = {}
local function foo ()
  local x = ffi.new(whatever)
  -- do some stuff to x
  anchoring[#anchoring] = x
end

-- Case 2 (anchored by table in return value of constructor)
local function bar ()
  local x = ffi.new(whatever)
  -- do some stuff to x
  return {key=x}
end

-- Case 3 (unanchored return of ffi.new())
local function baz ()
  local x = ffi.new(whatever)
  -- do some stuff to x
  return x
  -- oops! nothing references the memory from ffi.new when local x goes out
  -- of scope!
end

Demetri

Other related posts: