You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is expected behavior that objects assigned/written to MaybeUninit might leak at some point (if assume_init() or similar is not used). However, MaybeUninit::write_slice_cloned() returns a &mut [T] (which might be passed on to further functions, where its origin might not be apparent), and objects assigned to that might leak as well, which I think is less obvious.
I don't know if there is a way to improve the API to mitigate this problem, but I think at least the documentation should point out the potential leaking.
Currently, it is noted that already initialized values in MaybeUnint will not be dropped:
It is expected behavior that objects assigned/written to
MaybeUninit
might leak at some point (ifassume_init()
or similar is not used). However,MaybeUninit::write_slice_cloned()
returns a&mut [T]
(which might be passed on to further functions, where its origin might not be apparent), and objects assigned to that might leak as well, which I think is less obvious.playground example
I don't know if there is a way to improve the API to mitigate this problem, but I think at least the documentation should point out the potential leaking.
Currently, it is noted that already initialized values in
MaybeUnint
will not be dropped:rust/library/core/src/mem/maybe_uninit.rs
Line 923 in 780b094
However, it is not mentioned that assigning to the resulting slice might also lead to leaks.
MaybeUninit::write_slice_cloned()
was added in #79607Tracking issue: #79995
See also https://users.rust-lang.org/t/is-there-a-way-to-copy-t-into-mut-maybeuninit-t-without-unsafe/51301
The text was updated successfully, but these errors were encountered: