Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in test "mem::uninit_write_slice_cloned_no_drop" #80123

Merged
merged 2 commits into from
Dec 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions library/core/tests/mem.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::mem::*;

#[cfg(panic = "unwind")]
use std::rc::Rc;

#[test]
Expand Down Expand Up @@ -250,14 +251,19 @@ fn uninit_write_slice_cloned_mid_panic() {

#[test]
fn uninit_write_slice_cloned_no_drop() {
let rc = Rc::new(());
#[derive(Clone)]
struct Bomb;

impl Drop for Bomb {
fn drop(&mut self) {
panic!("dropped a bomb! kaboom")
}
}

let mut dst = [MaybeUninit::uninit()];
let src = [rc.clone()];
let src = [Bomb];

MaybeUninit::write_slice_cloned(&mut dst, &src);

drop(src);

assert_eq!(Rc::strong_count(&rc), 2);
forget(src);
}