diff --git a/src/lib.rs b/src/lib.rs index 72b2037..7761f6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,6 +94,9 @@ impl Stringish { /// Alternatively, use the [`Ish::ish`] method. #[must_use] pub fn new_owned(s: String) -> Self { + // converting to a `Vec` is necessary since `s.as_mut_ptr()` would call `str::as_mut_ptr` + // through deref coercion, which would only give us a pointer with provenance to the + // initialized part of the `String`, which is not enough to deallocate. let mut v = ManuallyDrop::new(s.into_bytes()); Self { // SAFETY: `v.as_mut_ptr()` is never null