It is possible for the reader to read freed memory.
The following example will panic at the assertion. The reader will read from the memory location previously occupied by write_buf which is now occupied by read_buf.
let (mut writer, mut reader) = pipe();
let mut write_buf = vec![0u8; 1024];
let _ = futures::poll!(writer.write_all(&mut write_buf));
drop(write_buf);
// Fill the space previously used by `write_buf`
let write_buf_overwrite = vec![1u8; 1024];
let mut read_buf = vec![0u8; 1024];
reader.read_exact(&mut read_buf).await.unwrap();
assert_eq!(read_buf, vec![0u8; 1024]);
drop(write_buf_overwrite);
To address this I’d suggest to copy the the write buffer into state.data instead of using *const u8.
It is possible for the reader to read freed memory.
The following example will panic at the assertion. The reader will read from the memory location previously occupied by
write_bufwhich is now occupied byread_buf.To address this I’d suggest to copy the the write buffer into
state.datainstead of using*const u8.