-
Notifications
You must be signed in to change notification settings - Fork 226
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
Double-free when dropping module as part of execution engine #60
Comments
Are you sure the segfault isn't because (in your example) you don't initialize a target? Modules don't call the llvm free method when they're owned by an EE, as in your example case: https://github.com/TheDan64/inkwell/blob/master/src/module.rs#L1339-L1343 |
Ugh I guess I minimised the example too much when pasting. Updated code in the description. But yes, the bug persist when initialising a target and is different from #59 (although I might be wrong about the root cause and it might be different from llvm-rs as well). Stacktrace:
|
Something weird is going on here, going to take a closer look this weekend. |
I think it is because let context = Context::create();
let module = context.create_module("sum");
let ee = module.create_jit_execution_engine(OptimizationLevel::None).unwrap();
drop(context);
drop(module); sigh This would be easily avoided with lifetimes if they were just But I guess for ergonomic's sake we should add the Feel free to make this change if you'd like (and let me know) otherwise I'll try and get to it sometime this weekend. We should also add a test case to show it is no longer a problem |
Describe the Bug
Current relationship between execution engine and the module can lead to double-free of a module in a "safe" API usage.
To Reproduce
Expected Behavior
Execution engine should either take ownership of the module or borrow it or module should be reference-counted internally or [use any other clear ownership semantic].
LLVM Version (please complete the following information):
Desktop (please complete the following information):
Additional Context
FWIW another Rust wrapper for LLVM had and fixed the same issue: TomBebbington/llvm-rs#25
The text was updated successfully, but these errors were encountered: