Re: Malloc -Z




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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-security
To unsubscribe, send any mail to "freebsd-security-unsubscribe@xxxxxxxxxxx"

_______________________________________________
freebsd-security@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-security
To unsubscribe, send any mail to "freebsd-security-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: nommu: handling anonymous mmap clearing in userspace rather than kernel
    ... uninitialised memory is prevented from accessing anything it wants to anyway. ... I would vote that the memset() should only be skipped if requested as there ... invokes the mmap() syscall directly would not get zeroed memory ... ...
    (Linux-Kernel)
  • Re: Malcolms new book - Chapter 1 review
    ... It is common for the OS to provided zeroed memory so calloc will not have to write to it if the memory has been freshly obtained from the OS, which is when there is a potential problem. ... Since you have to go the system specific route, you might as well go the system specific route of finding a way to disable lazy allocation. ...
    (comp.lang.c)
  • Re: nommu: handling anonymous mmap clearing in userspace rather than kernel
    ... uninitialised memory is prevented from accessing anything it wants to anyway. ... I would vote that the memset() should only be skipped if requested as there ... may be programs that call mmapexpecting the memory they're ... invokes the mmapsyscall directly would not get zeroed memory ... ...
    (Linux-Kernel)
  • Re: bootmem allocator
    ... clear memory allocated *only* if we really need this. ... Are there any users of bootmem which will allocate a significant amount of ... but it requires zeroed memory too. ...
    (Linux-Kernel)
  • Re: Overloading new[]
    ... It would be prudent to run destructors before freeing the memory. ...
    (microsoft.public.vc.language)