-
Notifications
You must be signed in to change notification settings - Fork 183
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
Storing unsafe references to L
#503
Comments
Some possible solutions:
|
This is a second test case related to this issue: local thread = coroutine.create(function ()
local uv = require "luv"
coroutine.yield();
end);
coroutine.resume(thread);
local uv = require "luv";
local t = uv.new_timer();
t:start(200, 0, function ()
t:start(200); -- throws an error
end);
uv.run("default"); The initial thread is not garbage collected, but is suspended. Because the timer callback is using the This demonstrates that option 4 in my previous comment would not be a valid solution to the problem. |
Thank you for the detailed report! |
I hear rumours of a release. Is a fix for this something we could get into it? I can try to take a look this week if it helps. I think from my list option 3 is the most robust solution. |
Yeah, I'd be interested in seeing what a solution might look like. (side note: I can reproduce the Valgrind error with the first test case, but not with the second test case [tried with Lua 5.1, Lua 5.4, and LuaJIT]) |
Hi - I think the proper solution is to add the lua context to userdata value field, using |
In a number of places luv stores a long-lived reference to
L
such as src/luv.c:712.This is not safe, however -
L
may refer to the current thread (coroutine) that the code is being called in, and threads are subject to garbage collection. After the thread (coroutine) is collected, the storedL
value points to freed memory.This materialized as a segfault in a complex application. It's hard to reduce to a simple test case that reliably segfaults, but running the below sample under valgrind will show the invalid memory accesses that are happening:
Valgrind output:
The text was updated successfully, but these errors were encountered: