Malloc -Z

Sean sean at gothic.net.au
Wed Jul 27 13:03:01 UTC 2011


On 27/07/2011, at 4:49 PM, grarpamp wrote:

> Was reading malloc(3) while chasing corruption suspects.
> Does the presence of -Z imply that without it, programs
> can be allocated dirty (non-zeroed) memory?
> If so, it seems running with -Z would be prudent if one cares.
> Therefore, what is the rough percent performance
> impact of -Z compared to default malloc?
> 

malloc(3) has never provided zeroed memory. If you need zeroed memory in C, you either need to zero it yourself using memset(3), or use calloc(3).

It's been part of the language standard for over 20 years now, and is the same in that regard on every platform that provides malloc(3).

What would be prudent as a developer (and is the default in CURRENT I believe) is to use J - it enforces the "memory from malloc(3) is not guaranteed to be zeroed." by specifically setting it to non-zero.


> Bonus:
> What would be needed to make the useful streams:
> /dev/one
> /dev/10
> /dev/01
> In addition to /dev/zero.
> _______________________________________________
> freebsd-security at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-security
> To unsubscribe, send any mail to "freebsd-security-unsubscribe at freebsd.org"



More information about the freebsd-security mailing list