arturoc / gstreamer1.0-rs

Idiomatic bindings for Gstreamer on Rust.
MIT License
36 stars 14 forks source link

Element.set is very unsafe #18

Closed Yoric closed 8 years ago

Yoric commented 8 years ago

If I read the code (and my segfaults) correctly, Element.set takes an argument of any type and passes it to g_object_set by simply coercing it to a pointer. That's a good way to segfault if I pass e.g. a str.

It might be possible to define a trait as follows

pub trait WithProperty<T> {
  fn set(&self, key: &str, value: T);
}

And implement WithProperty with the most common types.

arturoc commented 8 years ago

this is a great idea, i was discussing with someone else in another PR some days ago how to make this method safer. will look into it

Yoric commented 8 years ago

Also, I wonder about the memory-behavior of Element::set with respect to value. For example, if value is a Box (granted, probably not a good idea), since set takes ownership, the Box and its contents will be deallocated once we reach the end of the method, hence leaving a dangling pointer.

I'm not sure how to address this issue, or if it needs to be addressed at all.

Yoric commented 8 years ago

Mmmh... It looks like glib-rs is doing something along these lines: http://gtk-rs.org/docs/glib/value/struct.Value.html