-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Labels
Description
A problem exists when Lua garbage collector deletes a variable which has a reference in C++ but not in Lua. The following example shows a code which could end with a segmentation fault because of this issue:
function blah(db)
local gridfs = mongo.GridFS.New(db, "foo")
local file = gridfs:find_file("bar")
return function()
-- do whatever with file
print(file:chunk(0):data())
end
endThis code will produce arbitrary segmentation faults depending in the Lua garbage collection. The reference to gridfs only exists as local in the function blah. The returned closure captures the local file but not gridfs. So, at the end Lua garbage collector will delete gridfs variable because it is not referenced. Unfortunatelly, the GridFile C++ object contains a reference to this variable, but Lua is not acknowledged of that, and the call to file:chunk(0) will produce a segmentation fault.
Reactions are currently unavailable