[patch v4] malloc: avoid need for tcache == NULL checks

DJ Delorie dj@redhat.com
Fri Sep 5 19:39:24 GMT 2025


Florian Weimer <fweimer@redhat.com> writes:
>> +  if (av)
>> +    tcache = (tcache_perthread_struct *) _int_malloc (av, request2size (bytes));
>
> I think this is too long.

It's 80 chars, tweaked.

>> +  else
>> +    tcache = (tcache_perthread_struct *) __libc_malloc2 (bytes);
>>  
>> -  if (tcache != NULL)
>> +  if (tcache == NULL)
>> +    {
>> +      /* If the allocation failed, don't try again.  */
>> +      tcache_set_disabled ();
>> +    }
>> +  else
>
> Already set above.

No!  Setting tcache to the result of malloc undoes that and either
leaves it active (non NULL) or NULL - and a NULL tcache is not the same
as tcache_set_disabled, which sets tcache to a known pointer.



More information about the Libc-alpha mailing list