[patch v1] malloc: add malloc_zero_aborts tunable

Florian Weimer fweimer@redhat.com
Fri Feb 13 08:20:24 GMT 2026


* DJ Delorie:

> Paul Eggert <eggert@cs.ucla.edu> writes:
>> On 2/12/26 11:15, DJ Delorie wrote:
>>> +  if (bytes == 0 && mp_.malloc_zero_aborts)
>>> +    abort();
>>
>> This would cause malloc to fail to conform to the C standard, something 
>> that is far more likely to cause problems (even as an option) than to 
>> cure it. Nobody should use such an option.
>
> Agreed, but it's a tool for people who want to know if that part of the
> standard is affecting their code, and thus giving them a list of places
> to audit to make sure they're handling it correctly.
>
>> Also, it would slow down malloc.
>
> As I mentioned, I'd work on the tail recursion issue later.  The size
> would already be in a register (usually) and comparing it to zero is
> cheap enough, I'd add all the likelies etc.  I just had this thought and
> wanted to get feedback on it before I forgot it ;-)

We should really be using IFUNCs to select the entry points to the
malloc code.  Then this check can be part of a lightweight debug malloc
(along with the perturb code and other similar behaviors).  The IFUNC
resolvers would activate this code only if the tunables require it.

Thanks,
Florian



More information about the Libc-alpha mailing list