Skip to content

Commit 498d8db

Browse files
committed
fixed a potential soundness hole
1 parent 208bf1f commit 498d8db

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ macro_rules! try_zip_with {
128128
#[allow(unused_parens)]
129129
let ($($i),*) = $vec;
130130

131-
$crate::try_zip_with(
131+
$crate::try_zip_with_impl(
132132
$crate::list!(WRAP $($i),*),
133133
$($move)? |$crate::list!(PLACE $($i),*)| $($work)*
134134
)

src/vec/general_zip.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,19 +405,21 @@ impl<V, In: Tuple> ZipWithIter<V, In> {
405405
self.output.ptr.write(f(input)?);
406406
self.output.ptr = self.output.ptr.add(1);
407407
}
408-
}
409-
410-
// We don't want to drop `self` if dropping the excess elements panics
411-
// as that could lead to double drops
412-
self.should_free_output = false;
413408

414-
unsafe {
415-
// create the vector now, so that if we panic in drop, we don't leak it
416-
Ok(Vec::from_raw_parts(
417-
self.output.start as *mut V,
409+
// We don't want to drop `self` if dropping the excess elements panics
410+
// as that could lead to double drops
411+
self.should_free_output = false;
412+
413+
let (ptr, len, cap) = (
414+
self.output.start,
418415
self.initial_len,
419416
self.output.cap,
420-
))
417+
);
418+
419+
drop(self);
420+
421+
// create the vector now, so that if we panic in drop, we don't leak it
422+
Ok(Vec::from_raw_parts(ptr, len, cap))
421423
}
422424
}
423425
}

0 commit comments

Comments
 (0)