{"action":"created","issue":{"url":"https://api.github.com/repos/TheDan64/inkwell/issues/60","repository_url":"https://api.github.com/repos/TheDan64/inkwell","labels_url":"https://api.github.com/repos/TheDan64/inkwell/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/TheDan64/inkwell/issues/60/comments","events_url":"https://api.github.com/repos/TheDan64/inkwell/issues/60/events","html_url":"https://github.com/TheDan64/inkwell/issues/60","id":380064329,"node_id":"MDU6SXNzdWUzODAwNjQzMjk=","number":60,"title":"Double-free when dropping module as part of execution engine","user":{"login":"RReverser","id":557590,"node_id":"MDQ6VXNlcjU1NzU5MA==","avatar_url":"https://avatars2.githubusercontent.com/u/557590?v=4","gravatar_id":"","url":"https://api.github.com/users/RReverser","html_url":"https://github.com/RReverser","followers_url":"https://api.github.com/users/RReverser/followers","following_url":"https://api.github.com/users/RReverser/following{/other_user}","gists_url":"https://api.github.com/users/RReverser/gists{/gist_id}","starred_url":"https://api.github.com/users/RReverser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RReverser/subscriptions","organizations_url":"https://api.github.com/users/RReverser/orgs","repos_url":"https://api.github.com/users/RReverser/repos","events_url":"https://api.github.com/users/RReverser/events{/privacy}","received_events_url":"https://api.github.com/users/RReverser/received_events","type":"User","site_admin":false},"labels":[{"id":635498893,"node_id":"MDU6TGFiZWw2MzU0OTg4OTM=","url":"https://api.github.com/repos/TheDan64/inkwell/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/TheDan64/inkwell/milestones/1","html_url":"https://github.com/TheDan64/inkwell/milestone/1","labels_url":"https://api.github.com/repos/TheDan64/inkwell/milestones/1/labels","id":2612076,"node_id":"MDk6TWlsZXN0b25lMjYxMjA3Ng==","number":1,"title":"0.1.0","description":"Initial release of Inkwell","creator":{"login":"TheDan64","id":3749239,"node_id":"MDQ6VXNlcjM3NDkyMzk=","avatar_url":"https://avatars2.githubusercontent.com/u/3749239?v=4","gravatar_id":"","url":"https://api.github.com/users/TheDan64","html_url":"https://github.com/TheDan64","followers_url":"https://api.github.com/users/TheDan64/followers","following_url":"https://api.github.com/users/TheDan64/following{/other_user}","gists_url":"https://api.github.com/users/TheDan64/gists{/gist_id}","starred_url":"https://api.github.com/users/TheDan64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheDan64/subscriptions","organizations_url":"https://api.github.com/users/TheDan64/orgs","repos_url":"https://api.github.com/users/TheDan64/repos","events_url":"https://api.github.com/users/TheDan64/events{/privacy}","received_events_url":"https://api.github.com/users/TheDan64/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":15,"state":"open","created_at":"2017-06-29T12:53:37Z","updated_at":"2018-11-16T03:48:56Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2018-11-13T05:20:17Z","updated_at":"2018-11-17T04:12:35Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"**Describe the Bug**\r\nCurrent relationship between execution engine and the module can lead to double-free of a module in a \"safe\" API usage.\r\n\r\n**To Reproduce**\r\n```rust\r\nfn main() {\r\n    Target::initialize_native(&InitializationConfig::default()).unwrap();\r\n    let _execution_engine = {\r\n        let context = Context::create();\r\n        let module = context.create_module(\"sum\");\r\n        module.create_jit_execution_engine(OptimizationLevel::None).unwrap()\r\n    };\r\n}\r\n```\r\n\r\n**Expected Behavior**\r\nExecution 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].\r\n\r\n**LLVM Version (please complete the following information):**\r\n - LLVM Version: 7.0.0\r\n - Inkwell Branch Used: master\r\n\r\n**Desktop (please complete the following information):**\r\n - OS: macOS 10.14 (Mojave)\r\n\r\n**Additional Context**\r\nFWIW another Rust wrapper for LLVM had and fixed the same issue: https://github.com/TomBebbington/llvm-rs/issues/25\r\n"},"comment":{"url":"https://api.github.com/repos/TheDan64/inkwell/issues/comments/439586343","html_url":"https://github.com/TheDan64/inkwell/issues/60#issuecomment-439586343","issue_url":"https://api.github.com/repos/TheDan64/inkwell/issues/60","id":439586343,"node_id":"MDEyOklzc3VlQ29tbWVudDQzOTU4NjM0Mw==","user":{"login":"TheDan64","id":3749239,"node_id":"MDQ6VXNlcjM3NDkyMzk=","avatar_url":"https://avatars2.githubusercontent.com/u/3749239?v=4","gravatar_id":"","url":"https://api.github.com/users/TheDan64","html_url":"https://github.com/TheDan64","followers_url":"https://api.github.com/users/TheDan64/followers","following_url":"https://api.github.com/users/TheDan64/following{/other_user}","gists_url":"https://api.github.com/users/TheDan64/gists{/gist_id}","starred_url":"https://api.github.com/users/TheDan64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheDan64/subscriptions","organizations_url":"https://api.github.com/users/TheDan64/orgs","repos_url":"https://api.github.com/users/TheDan64/repos","events_url":"https://api.github.com/users/TheDan64/events{/privacy}","received_events_url":"https://api.github.com/users/TheDan64/received_events","type":"User","site_admin":false},"created_at":"2018-11-17T04:12:35Z","updated_at":"2018-11-17T04:12:35Z","author_association":"OWNER","body":"I think it is because `Context` is the primary owner of all data, so the last rc of context goes away with the module, and then the EE is no longer valid. You can reproduce it this way:\r\n\r\n```rust\r\nlet context = Context::create();\r\nlet module = context.create_module(\"sum\");\r\nlet ee = module.create_jit_execution_engine(OptimizationLevel::None).unwrap();\r\n\r\ndrop(context);\r\ndrop(module);\r\n```\r\n\r\n*sigh* This would be easily avoided with lifetimes if they were just `Context` -> `&Module` -> `&ExecutionEngine`\r\n\r\nBut I guess for ergonomic's sake we should add the `Context` to the EE.\r\n\r\nFeel 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"}}
{"actor":{"display_login":"TheDan64"}}