bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

malloca, freea are not thread-safe


From: Florian Weimer
Subject: malloca, freea are not thread-safe
Date: Wed, 10 Jan 2018 15:02:17 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

The mmalloca function used to implement malloca accesses a static global array without synchronization:

#define HASH_TABLE_SIZE 257
static void * mmalloca_results[HASH_TABLE_SIZE];
…
mmalloca (size_t n)
{
…
    /* Enter p into the hash table.  */
          slot = (uintptr_t) p % HASH_TABLE_SIZE;
          h->next = mmalloca_results[slot];
          mmalloca_results[slot] = p;

freea also causes valgrind warnings because it contains an out-of-bounds access. This is very undesirable because it will cause programmers to miss real bugs.

This code has been copied into libunistring and results in a thread safety hazard there.

Thanks,
Florian



reply via email to

[Prev in Thread] Current Thread [Next in Thread]