|
|
|
|
|
by pedrocr
4969 days ago
|
|
>because calloc zeros the memory and therefore writes to each page. One does not imply the other. Internally what the kernel can do is link the page address it gives you to the zero page and mark it as copy on write. Only when you actually write to it will it allocate an actual page to back it. Only if your libc implements calloc as malloc+memset would this be a problem. Does glibc do that? In fact the copy on write is probably also done on malloc as well. Even though the manpage implies different behavior (malloc doesn't guarantee setting the memory to 0, while calloc does) I don't think any sane kernel will give you someone else's free()'d memory. It would be a security leak. |
|
I just checked (see my reply to the parent) and it doesn't.
> In fact the copy on write is probably also done on malloc as well. [...] I don't think any sane kernel will give you someone else's free()'d memory
You won't get someone else's freed memory but you're quite likely to get your own back and in that case it won't necessarily be zeroed.