-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Invalid free memory while dropping #67179
Comments
See #63338. |
Closing since this is not a supported configuration |
Ok, sounds clear. (#63338 (comment)) This means articles and threads like https://users.rust-lang.org/t/how-to-write-plugins-in-rust/6325/18 , https://michael-f-bryan.github.io/rust-ffi-guide/dynamic_loading.html , https://s3.amazonaws.com/temp.michaelfbryan.com/dynamic-loading/index.html are not intend to be used within the rust ecosystem. |
-------------------
Edit
I guess this bug will not get fixed by any hook, only by fixing it in the library. Or, at least, i did not find a workaround myself. The problem lies in the way BTreeMap is coded. See the link.
rust/src/liballoc/collections/btree/node.rs
Line 130 in a605441
The static reference is embedded in each binary after compilation and linking process. So, i guess, the "static EMPTY_ROOT_NODE" in main exe and in the library refers to different location. See this output below.
Passing a BTreeMap created in main and passing it to Foo led to a bad behavior because the static reference do not point to the same memory location while dropping. I might be wrong but it make sense to me according to the previous output.
-------------------
Hello,
Basically, my program is dynamically loading a library (cdylib) and retrieve a factory object (Factory design pattern). No problem here.
Then, on demand, a new object with the Foo trait is created. Again, nothing wrong with that. However, moving an object created in the main program to the Foo object instance, lead to an invalid free memory, according to valgrind, when dropping the Foo object.
Edit : This also exist on stable build --> rustc 1.39.0 (2019-11-04)
Edit : Trying to change ["cdylib"] to ["dylib"] lead to a strange behavior : the library is loaded via 'cargo run' but no more via a regular exec by the shell (thus also by valgrind). To let you know that i did not found an understandable workaround.
Here the code:
Common traits definition - 'common' crate
Cdynlib... Rust book was around...
corresponding TOML
And finally, main program here
and corresponding TOML
Note : i had an issue with loadlibrary because of the created Symbol lifetime. Here is another matter.
Final note : this bug does not appear on zero-sized type (replacing BTreeMap by ZST_Object {} in signatures ).
The text was updated successfully, but these errors were encountered: