File tree 2 files changed +6
-1
lines changed
2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,10 @@ fn test_os_string_clear() {
26
26
#[ test]
27
27
fn test_os_string_leak ( ) {
28
28
let os_string = OsString :: from ( "have a cake" ) ;
29
+ let ( len, cap) = ( os_string. len ( ) , os_string. capacity ( ) ) ;
29
30
let leaked = os_string. leak ( ) ;
30
31
assert_eq ! ( leaked. as_encoded_bytes( ) , b"have a cake" ) ;
32
+ unsafe { drop ( String :: from_raw_parts ( leaked as * mut OsStr as _ , len, cap) ) }
31
33
}
32
34
33
35
#[ test]
Original file line number Diff line number Diff line change @@ -128,9 +128,12 @@ fn into() {
128
128
129
129
#[ test]
130
130
fn test_pathbuf_leak ( ) {
131
- let buf = PathBuf :: from ( "/have/a/cake" . to_owned ( ) ) ;
131
+ let string = "/have/a/cake" . to_owned ( ) ;
132
+ let ( len, cap) = ( string. len ( ) , string. capacity ( ) ) ;
133
+ let buf = PathBuf :: from ( string) ;
132
134
let leaked = buf. leak ( ) ;
133
135
assert_eq ! ( leaked. as_os_str( ) . as_encoded_bytes( ) , b"/have/a/cake" ) ;
136
+ unsafe { drop ( String :: from_raw_parts ( leaked. as_mut_os_str ( ) as * mut OsStr as _ , len, cap) ) }
134
137
}
135
138
136
139
#[ test]
You can’t perform that action at this time.
0 commit comments