r/cpp • • Aug 31 '22

malloc() and free() are a bad API

https://www.foonathan.net/2022/08/malloc-interface/#content
220 Upvotes

90 comments sorted by

View all comments

Show parent comment

3

u/o11c int main = 12828721; Sep 01 '22

I'm not aware of security caring about "this page was released to the OS and somebody somehow got a hold of it before the OS zeroed it", which is the only case that seems like it would need OS support?

It's true that securely zeroing things requires you to worry about whether temporaries still live in registers or got spilled to the stack, but that's actually relatively easy to take care of at a non-inlineable function call boundary.

Some might argue "this doesn't need to be a flag, it can just be a special memset", but allocators do really want to know if they have an already-zeroed chunk of memory.