Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Fix FromGlibContainer double freeing #160

Merged
merged 1 commit into from May 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/translate.rs
Expand Up @@ -911,9 +911,7 @@ for Vec<T> {
res.push(from_glib_full(*ptr));
ptr = ptr.offset(1);
}
//See g_resource_enumerate_children
//glib_ffi::g_free(orig_ptr as *mut _);
glib_ffi::g_strfreev(orig_ptr as *mut _);
glib_ffi::g_free(orig_ptr as *mut _);
res
}
}
Expand Down Expand Up @@ -1145,4 +1143,15 @@ mod tests {
assert_eq!(map.get("B"), Some(&"2".into()));
assert_eq!(map.get("C"), Some(&"3".into()));
}

#[test]
fn string_array() {
let v = vec!["A".to_string(), "B".to_string(), "C".to_string()];
let stash = v.to_glib_none();
let ptr: *mut *mut c_char = stash.0;
let ptr_copy = unsafe { glib_ffi::g_strdupv(ptr) };

let actual: Vec<String> = unsafe{ FromGlibPtrContainer::from_glib_full(ptr_copy) };
assert_eq!(v, actual);
}
}