ebassi / taglib-rust

TagLib bindings for Rust
MIT License
27 stars 11 forks source link

Tag's lifetime is dependent on File, but no error occurs with dangling reference #1

Closed czipperz closed 8 years ago

czipperz commented 8 years ago

The Drop trait implemented for taglib::File will destruct the Tag even though Rust thinks their lifetimes are independent (https://github.com/ebassi/taglib-rust/blob/master/src/lib.rs#L213).

Here is some example code of the problem (where "song.mp3" is a real, valid mp3 file):

extern crate taglib;

fn main() {
    let tags = get_tags(&"song.mp3".to_string());
    tags.artist();
}

fn get_tags(fname: &String) -> taglib::Tag {
    let file = taglib::File::new(&fname).unwrap();
    file.tag().unwrap()
}

Running this will result in a signal 11 on my machine:

$ cargo run --verbose
       Fresh libc v0.1.12
       Fresh taglib v0.1.0
       Fresh test v0.1.0 (file:///home/czipperz/test)
     Running `target/debug/test`
Process didn't exit successfully: `target/debug/test` (signal: 11)
czipperz commented 8 years ago

You'll need to push this to http://crates.io

czipperz commented 8 years ago

Thanks for the commit!