8 ms·
Yeah, even the official Rust book points it out and if my memory serves me right (not punintended) also gives an example in the form of creating a memory leak (
by emilbratt 9mo ago
Yeah, even the official Rust book points it out and if my memory serves me right (not punintended) also gives an example in the form of creating a memory leak (not to be confused with memory unsafe).
- spookie 9mo agoA memory leak can be unsafe though.
- 201984 9mo agoThen why is Box::leak not marked unsafe?
- estebank 9mo ago"unsafe" or `unsafe`? One is the general meaning of the word, the latter is "it invokes undefined-behavior".
- spookie 9mo agoAs "unsafe". An example would be of how AMD GPUs some time ago didn't free a programs' last rendered buffers and you could see the literal last frame in its entirety. Fun stuff. Could've been clearer above.
- yuriks 9mo agoThat is not a memory leak though! That's using/exposing an uninitialized buffer, which can happen even if you allocate and free your allocations correctly. Leaking the buffer would prevent the memory region from being allocated by another application, and would in fact prevent that from happening. This is also something that Rust does protect against in safe code, by requiring initialization of all memory before use, or using MaybeUninit for buffers that aren't, where reading the buffer or asserting that it has been initialized is an unsafe operation.