Fix memory leak in owned_to_vec (#773)

This commit is contained in:
venomousmoog
2025-03-05 10:44:40 +01:00
committed by GitHub
parent e0f3a25fae
commit 36675436cc
2 changed files with 22 additions and 5 deletions
+13
View File
@@ -1619,6 +1619,19 @@ fn owned_to_vec() {
assert_eq!(drop_counter.get(), 1);
}
#[test]
fn owned_into_vec() {
let drop_counter = SharedAtomicCounter::new();
let buf: [u8; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let owner = OwnedTester::new(buf, drop_counter.clone());
let b1 = Bytes::from_owner(owner);
let v1: Vec<u8> = b1.into();
assert_eq!(&v1[..], &buf[..]);
// into() vec will copy out of the owner and drop it
assert_eq!(drop_counter.get(), 1);
}
#[test]
#[cfg_attr(not(panic = "unwind"), ignore)]
fn owned_safe_drop_on_as_ref_panic() {