Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20f15f4

Browse files
fixed memory leaks in PathBuf::leak & OsString::leak tests
1 parent85aa4b6 commit20f15f4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎std/src/ffi/os_str/tests.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ fn test_os_string_clear() {
2626
#[test]
2727
fntest_os_string_leak(){
2828
let os_string =OsString::from("have a cake");
29+
let(len, cap) =(os_string.len(), os_string.capacity());
2930
let leaked = os_string.leak();
3031
assert_eq!(leaked.as_encoded_bytes(),b"have a cake");
32+
unsafe{drop(String::from_raw_parts(leakedas*mutOsStras_, len, cap))}
3133
}
3234

3335
#[test]

‎std/src/path/tests.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ fn into() {
128128

129129
#[test]
130130
fntest_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);
132134
let leaked = buf.leak();
133135
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*mutOsStras_, len, cap))}
134137
}
135138

136139
#[test]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp