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 @@ -982,16 +982,18 @@ pub fn recvmmsg<'a, I>(
982
982
983
983
let mut output: Vec < libc:: mmsghdr > = Vec :: with_capacity ( num_messages) ;
984
984
985
- // Addresses should be pre-allocated and never change the address during building
986
- // of the input data for `recvmmsg`
987
- let mut addresses: Vec < sockaddr_storage > = vec ! [ unsafe { mem:: zeroed( ) } ; num_messages] ;
985
+ // Addresses should be pre-allocated. pack_mhdr_to_receive will store them
986
+ // as raw pointers, so we may not move them. Turn the vec into a boxed
987
+ // slice so we won't inadvertently reallocate the vec.
988
+ let mut addresses = vec ! [ mem:: MaybeUninit :: uninit( ) ; num_messages]
989
+ . into_boxed_slice ( ) ;
988
990
989
991
let results: Vec < _ > = iter. enumerate ( ) . map ( |( i, d) | {
990
992
let ( msg_controllen, mhdr) = unsafe {
991
993
pack_mhdr_to_receive (
992
994
d. iov . as_ref ( ) ,
993
995
& mut d. cmsg_buffer ,
994
- & mut addresses[ i] ,
996
+ addresses[ i] . as_mut_ptr ( ) ,
995
997
)
996
998
} ;
997
999
@@ -1017,7 +1019,7 @@ pub fn recvmmsg<'a, I>(
1017
1019
1018
1020
Ok ( output
1019
1021
. into_iter ( )
1020
- . zip ( addresses. into_iter ( ) )
1022
+ . zip ( addresses. iter ( ) . map ( |addr| unsafe { addr . assume_init ( ) } ) )
1021
1023
. zip ( results. into_iter ( ) )
1022
1024
. map ( |( ( mmsghdr, address) , ( msg_controllen, cmsg_buffer) ) | {
1023
1025
unsafe {
You can’t perform that action at this time.
0 commit comments