Fix image property accessor to copy C string

cargo test passes
This commit is contained in:
Nathan Fiedler
2016-01-02 19:57:39 -08:00
parent 19377db422
commit 7bc3f274d2
3 changed files with 8 additions and 6 deletions

View File

@ -99,7 +99,7 @@ impl MagickWand {
}
/// Retrieve the named image property value.
pub fn get_image_property(&self, name: &str) -> Result<&str, &'static str> {
pub fn get_image_property(&self, name: &str) -> Result<String, &'static str> {
let c_name = CString::new(name).unwrap();
let result = unsafe {
bindings::MagickGetImageProperty(self.wand, c_name.as_ptr())
@ -107,11 +107,9 @@ impl MagickWand {
let value = if result.is_null() {
Err("missing property")
} else {
// convert (and copy) the C string to a Rust string
let cstr = unsafe { CStr::from_ptr(result) };
match cstr.to_str() {
Ok(v) => Ok(v),
Err(_) => Err("invalid value")
}
Ok(cstr.to_string_lossy().into_owned())
};
unsafe {
bindings::MagickRelinquishMemory(result as *mut c_void);