[patch v1] malloc: add malloc_zero_aborts tunable
Carlos O'Donell
carlos@redhat.com
Fri Feb 13 14:46:46 GMT 2026
On 2/13/26 3:20 AM, Florian Weimer wrote:
> * 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.
Agreed. That's a great way to mitigate the performance impact.
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list