Malloc Never Fails (2012)
scvalex.net
Malloc Never Fails (2012)
1–10 of 165 posts
Re: Malloc Never Fails (2012)
#2malloc fails with ulimit
Re: Malloc Never Fails (2012)
#3Another thing to keep in mind, though 32 bit is less and less common over time, malloc would probably fail on a 32 bit process that is out of address space.
Re: Malloc Never Fails (2012)
#4malloc fails with a negative argument
Re: Malloc Never Fails (2012)
#5Malloc allocates virtual memory. The original article had to issue a correction at the end: "I was wrong about why malloc finally failed! @GodmarBack observes, in the comments, that x64 systems only have an address space of 48 bits, which comes out to about 131000 GB. So, on my machine at least, the malloc finally failed because of address space exhaustion."
Re: Malloc Never Fails (2012)
#6malloc fails with ulimit
Very relevant, because containers are often under what basically is ulimit.
Not that you can do much when malloc fails...
Re: Malloc Never Fails (2012)
#7The title here is just blatantly false; there are certainly some scenarios in which it won't fail, but many in which it will. The author is aware of this since he fixes the claim toward the end:
> To clarify, the surprising behaviour malloc has does not mean we should ignore its return value. We just need to be careful because malloc returning successfully does not always mean that we can use the requested memory.
It's worth pointing out that if you turn overcommit off (https://www.kernel.org/doc/Documentation/vm/overcommit-accou...) you will, in fact, get this guarantee
Re: Malloc Never Fails (2012)
#8malloc fails with a negative argument
malloc takes a size_t, which is unsigned. A "negative" argument is just something that's absurdly large.
Re: Malloc Never Fails (2012)
#9Another thing to keep in mind, though 32 bit is less and less common over time, malloc would probably fail on a 32 bit process that is out of address space.
Raspberry Pis almost always run 32 bit OSes, so that's a common place to encounter 32-bit.
Re: Malloc Never Fails (2012)
#10> Section III of this Phrack article is a down to earth description of how the glibc malloc implementation works, if you’re curious.
This is probably outdated, given that it was written in 2009.