Closed FlorentinoJink closed 7 months ago
Try
let mut company2_ws = WideString::with_capacity(MAX_PATH);
let company2 = company2_ws.as_mut_ptr()
instead of
let mut company2 = WideString::with_capacity(MAX_PATH).as_mut_ptr();
and similarly for other instances of this. The way you're doing it right now the WideString
is allocated, the mutable pointer is obtained from it and then the WideString
is freed at the end of the statement, because it itself is not assigned to anything. Then the code goes on to use-after-free this now-dangling pointer.
As a general rule of thumb I would recommend converting to raw pointers at the very last moment (e.g. in a function call arguments), as this way you get most out of the static analyses that Rust provides -- raw pointers are not included into those!)
All that said, these issues are not libloading specifically. I would like to point you at users.rust-lang.org
or a similar forum for questions about use of Rust.
Thanks!
This my rust code
this my toml
and this my windows cpp dll
I just return a value. when I run it, as long as I operate on the pointer created using WideString::with_capacity, the dynamic library unloads and crashes, but if I use an array, there is no such issue. if I load the dynamic library, it crashes.
if not dynamic library, not crash
Why does memory operation crash after loading a dynamic library, and why doesn't it crash when switching to an array?