pipewire: properties!{} macro uses freed memory
Thanks clippy:
warning: getting the inner pointer of a temporary `CString`
--> pipewire/src/properties.rs:58:57
|
58 | std::ffi::CString::new($k).unwrap().as_ptr(),
| ----------------------------------- ^^^^^^ this pointer will be invalid
| |
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
...
219 | let props = properties! {
| _____________________-
220 | | "K0" => "V0"
221 | | };
| |_________- in this macro invocation
|
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
= help: for more information, see https://doc.rust-lang.org/reference/destructors.html
= note: `#[warn(temporary_cstring_as_ptr)]` on by default
= note: this warning originates in the macro `properties` (in Nightly builds, run with -Z macro-backtrace for more info)
This means that we're freeing the CStrings before calling the functions, the pointers point to freed memory.
The macro code is here: https://gitlab.freedesktop.org/pipewire/pipewire-rs/-/blob/main/pipewire/src/properties.rs#L53
I can't figure out how to solve this. Because we're using a variadic macro, it doesn't seem possible to bind each argument to a variable before the function call.
Rust RFC 3086 could help because we could stick all args in a Vector and then index it with the current repition number, but the implementation is still unstable.