{"action":"created","issue":{"url":"https://api.github.com/repos/craigbarnes/lua-gumbo/issues/44","labels_url":"https://api.github.com/repos/craigbarnes/lua-gumbo/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/craigbarnes/lua-gumbo/issues/44/comments","events_url":"https://api.github.com/repos/craigbarnes/lua-gumbo/issues/44/events","html_url":"https://github.com/craigbarnes/lua-gumbo/issues/44","id":72734266,"number":44,"title":"Use finalizer to avoid memory leaks","user":{"login":"craigbarnes","id":494077,"avatar_url":"https://avatars.githubusercontent.com/u/494077?v=3","gravatar_id":"","url":"https://api.github.com/users/craigbarnes","html_url":"https://github.com/craigbarnes","followers_url":"https://api.github.com/users/craigbarnes/followers","following_url":"https://api.github.com/users/craigbarnes/following{/other_user}","gists_url":"https://api.github.com/users/craigbarnes/gists{/gist_id}","starred_url":"https://api.github.com/users/craigbarnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigbarnes/subscriptions","organizations_url":"https://api.github.com/users/craigbarnes/orgs","repos_url":"https://api.github.com/users/craigbarnes/repos","events_url":"https://api.github.com/users/craigbarnes/events{/privacy}","received_events_url":"https://api.github.com/users/craigbarnes/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/craigbarnes/lua-gumbo/labels/Bug","name":"Bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-05-03T02:23:55Z","updated_at":"2015-11-23T03:37:13Z","closed_at":null,"body":"As [mentioned] by @daurnimator, the bindings currently leak the heap-allocated `GumboOutput` if an error is thrown during parsing (unlikely, [but][] [possible]). A finalizer should be used (via [`ffi.gc`] or [`__gc`]) to prevent leaks even in the case of errors.\r\n\r\n[but]: https://github.com/craigbarnes/lua-gumbo/blob/5e333e78fb583fd6d70ddc65b0145edc74704f62/gumbo/parse.c#L159\r\n[possible]: https://github.com/craigbarnes/lua-gumbo/blob/5e333e78fb583fd6d70ddc65b0145edc74704f62/gumbo/parse.c#L219\r\n[mentioned]: https://github.com/craigbarnes/lua-gumbo/issues/41#issuecomment-87640880\r\n[`ffi.gc`]: http://luajit.org/ext_ffi_api.html#ffi_gc\r\n[`__gc`]: http://www.lua.org/manual/5.2/manual.html#2.5.1"},"comment":{"url":"https://api.github.com/repos/craigbarnes/lua-gumbo/issues/comments/158846169","html_url":"https://github.com/craigbarnes/lua-gumbo/issues/44#issuecomment-158846169","issue_url":"https://api.github.com/repos/craigbarnes/lua-gumbo/issues/44","id":158846169,"user":{"login":"craigbarnes","id":494077,"avatar_url":"https://avatars.githubusercontent.com/u/494077?v=3","gravatar_id":"","url":"https://api.github.com/users/craigbarnes","html_url":"https://github.com/craigbarnes","followers_url":"https://api.github.com/users/craigbarnes/followers","following_url":"https://api.github.com/users/craigbarnes/following{/other_user}","gists_url":"https://api.github.com/users/craigbarnes/gists{/gist_id}","starred_url":"https://api.github.com/users/craigbarnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigbarnes/subscriptions","organizations_url":"https://api.github.com/users/craigbarnes/orgs","repos_url":"https://api.github.com/users/craigbarnes/repos","events_url":"https://api.github.com/users/craigbarnes/events{/privacy}","received_events_url":"https://api.github.com/users/craigbarnes/received_events","type":"User","site_admin":false},"created_at":"2015-11-23T03:37:13Z","updated_at":"2015-11-23T03:37:13Z","body":"I was thinking about storing the pointer as a lightuserdata field and checking/freeing that in `__gc`. The metatable would have to be set before anything else though, yes. I started implementing it a while back and gave up. I really should close this issue before I release 0.4 though."}}