I have written a C program than iterates hundreds of thousands of times. There might be several million calls to malloc(), realloc() and free() after so many iterations.
There is no memory leak. The program does NOT crash at realloc(). It only crashes at malloc().
The program runs perfectly for many hundrends of thousands of iterations, with every function getting called several times each iteration. Then, for no reason I can discern, it crashes at some random malloc().
I've ony seen the crash occur near the beginning of a function call. Probably this is because most, if not all, occurences of malloc() occur near the start of a function.
The crash does not occur at the same malloc() every time. If I use the same random seed, the crash occurs at the same malloc(), and after exactly the same number of iterations. However, if I adjust the random seed, the crash will occur at a probably different malloc() after a different number of iterations.
Any ideas on what causes this?