So, you initially set size
to START_SIZE
, which is 100,000. Then when you use that up, you try to allocate sizeof(word) * size * GROW
bytes. sizeof(word)
is presumably 16 bytes; we know that size
is 100000, and GROW
is 1000. So that works out to enough space for 100,000,000 entries, of which you say you will use 235,000. That seems like the allocation is a bit on the generous side.
The total space for 100,000,000 entries is 1,600,000,000 bytes. That seems like a lot, although these days many desktop machines could handle that. But it doesn't seem too surprising that realloc
fails.
Perhaps you should make GROW
something more reasonable, like 2.
By the way, once you've established that word_storage is NULL, there is no point in calling free(word_storage)
. It does no harm, since free(NULL)
is a no-op, but it also does no good for the same reason.