Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected garbage collection #29

Open
pakozm opened this issue May 6, 2014 · 0 comments
Open

Unexpected garbage collection #29

pakozm opened this issue May 6, 2014 · 0 comments
Labels

Comments

@pakozm
Copy link
Contributor

pakozm commented May 6, 2014

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
end

This 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.

@pakozm pakozm added the bug label May 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant