chris-zen / coremidi

CoreMIDI library for Rust
https://chris-zen.github.io/coremidi/coremidi/
MIT License
75 stars 20 forks source link

CoreFoundation objects over-released in Properties #23

Closed jasongrlicky closed 4 years ago

jasongrlicky commented 4 years ago

When auditing this crate to incorporate it into a project, I found issues around CFStringRefs being over-released in certain circumstances when creating *-Property structs using ::new().

The problem would arise when using an incorrect user-supplied string when initializing a property, making the following line of code result in a panic with a SIGILL:

let name = destination.get_property_string("NotARealPropertyName").unwrap();

So when boiled down, the problem is basically the same one as in https://github.com/chris-zen/coremidi/issues/17 - a CFString was created and then immediately dropped in -Property::new(), meaning any CFStringRefs created from it are now invalid. The solution was to abstract over -Propertys now owning a CFString or a CFStringRef, depending of if the Property struct was initialized with a constant from CoreMidi or a user-supplied string. This is what the PropertyKeyStorage struct does.