File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -941,16 +941,18 @@ pub fn recvmmsg<'a, I>(
941
941
942
942
let mut output: Vec < libc:: mmsghdr > = Vec :: with_capacity ( num_messages) ;
943
943
944
- // Addresses should be pre-allocated and never change the address during building
945
- // of the input data for `recvmmsg`
946
- let mut addresses: Vec < sockaddr_storage > = vec ! [ unsafe { mem:: zeroed( ) } ; num_messages] ;
944
+ // Addresses should be pre-allocated. pack_mhdr_to_receive will store them
945
+ // as raw pointers, so we may not move them. Turn the vec into a boxed
946
+ // slice so we won't inadvertently reallocate the vec.
947
+ let mut addresses = vec ! [ mem:: MaybeUninit :: uninit( ) ; num_messages]
948
+ . into_boxed_slice ( ) ;
947
949
948
950
let results: Vec < _ > = iter. enumerate ( ) . map ( |( i, d) | {
949
951
let ( msg_controllen, mhdr) = unsafe {
950
952
pack_mhdr_to_receive (
951
953
d. iov . as_ref ( ) ,
952
954
& mut d. cmsg_buffer ,
953
- & mut addresses[ i] ,
955
+ addresses[ i] . as_mut_ptr ( ) ,
954
956
)
955
957
} ;
956
958
@@ -976,7 +978,7 @@ pub fn recvmmsg<'a, I>(
976
978
977
979
Ok ( output
978
980
. into_iter ( )
979
- . zip ( addresses. into_iter ( ) )
981
+ . zip ( addresses. iter ( ) . map ( |addr| unsafe { addr . assume_init ( ) } ) )
980
982
. zip ( results. into_iter ( ) )
981
983
. map ( |( ( mmsghdr, address) , ( msg_controllen, cmsg_buffer) ) | {
982
984
unsafe {
You can’t perform that action at this time.
0 commit comments