fixed memory leaks in PathBuf::leak & OsString::leak tests
This commit is contained in:
parent
fd5777c4c5
commit
2bdc53b153
@ -26,8 +26,10 @@ fn test_os_string_clear() {
|
||||
#[test]
|
||||
fn test_os_string_leak() {
|
||||
let os_string = OsString::from("have a cake");
|
||||
let (len, cap) = (os_string.len(), os_string.capacity());
|
||||
let leaked = os_string.leak();
|
||||
assert_eq!(leaked.as_encoded_bytes(), b"have a cake");
|
||||
unsafe { drop(String::from_raw_parts(leaked as *mut OsStr as _, len, cap)) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -128,9 +128,12 @@ fn into() {
|
||||
|
||||
#[test]
|
||||
fn test_pathbuf_leak() {
|
||||
let buf = PathBuf::from("/have/a/cake".to_owned());
|
||||
let string = "/have/a/cake".to_owned();
|
||||
let (len, cap) = (string.len(), string.capacity());
|
||||
let buf = PathBuf::from(string);
|
||||
let leaked = buf.leak();
|
||||
assert_eq!(leaked.as_os_str().as_encoded_bytes(), b"/have/a/cake");
|
||||
unsafe { drop(String::from_raw_parts(leaked.as_mut_os_str() as *mut OsStr as _, len, cap)) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user