Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A memory leak can be unsafe though.


Then why is Box::leak not marked unsafe?


"unsafe" or `unsafe`? One is the general meaning of the word, the latter is "it invokes undefined-behavior".


As "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.


That 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.


It's a security hole. Rust doesn't prevent you from writing unsafe code that reads it. The bug wasn't that it could be read by a well conforming language, it was that it was handed off uninitialized to use space at all.


Fair, bad example.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: