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

DJ Delorie dj@redhat.com
Thu Sep 4 03:33:59 GMT 2025


Florian Weimer <fweimer@redhat.com> writes:
>> +#if USE_TCACHE
>> +		  if (__glibc_unlikely (tcache_inactive ()))
>> +		    tcache_init (av);
>> +#endif
>>  		  /* While bin not empty and tcache not full, copy chunks.  */
>>  		  while (tcache->num_slots[tc_idx] != 0 && (tc_victim = *fb) != NULL)
>>  		    {
>
> I don't think you can call into malloc at this point because it may
> invalidate the bin contents.  So the while loop should be in the else
> part of the if (with a comment that tcache_init sets up the cache for
> future calls).

I checked all three, and the tcache priming code only happens at a point
where the arena is stable, and the only variables we use across that
call wouldn't change anyway (pointers to bins, and the bins never move).
I think these are safe.  Data should be consistent because it's all
happening in one thread under a lock.



More information about the Libc-alpha mailing list