Hi,
In libpulse_binding::mainloop::api::standard::Mainloop (this line) and libpulse_binding::mainloop::api::threaded::Mainloop (this line), there is the function get_api which returns a borrow to the API vtable. I think the lifetime annotations of this function are incorrect and could lead to unexpected behavior.
pub fn get_api<'a>(&self) -> &'a ::mainloop::api::MainloopApi {
...
}
The returned borrow can live even after the Mainloop is freed and the Api is destroyed. As the function's docstring says, "No need to free the API as it is owned by the loop and is destroyed when the loop is freed."
I believe that something like this shouldn't be allowed to compile:
let mut mainloop = Mainloop::new().expect("Failed to create Mainoop");
let api: &MainloopApi = mainloop.get_api();
drop(mainloop); // Also frees API vtable
// Use api here
Changing the function signature to this would solve the issue and prevent the above code from compiling.
pub fn get_api(&self) -> & ::mainloop::api::MainloopApi
Hi,
In
libpulse_binding::mainloop::api::standard::Mainloop(this line) andlibpulse_binding::mainloop::api::threaded::Mainloop(this line), there is the functionget_apiwhich returns a borrow to the API vtable. I think the lifetime annotations of this function are incorrect and could lead to unexpected behavior.The returned borrow can live even after the Mainloop is freed and the Api is destroyed. As the function's docstring says, "No need to free the API as it is owned by the loop and is destroyed when the loop is freed."
I believe that something like this shouldn't be allowed to compile:
Changing the function signature to this would solve the issue and prevent the above code from compiling.