The program was not failing on the first realloc. It was tying up memory as the program repeated itself and eventually exhausting all memory. This is when it was crashing.
Printable View
The program was not failing on the first realloc. It was tying up memory as the program repeated itself and eventually exhausting all memory. This is when it was crashing.
Valgrind has to hold onto the memory so that it (and you) can spot any "use-after-free" memory problems you may have.
Aside from Valgrind I am still leaking memory due to constant reallocation. I guess this is just not a valid approach for a large amount of memory reallocation. I think my strategy will be to just malloc a very large cache of 256k blocks at the start of the daemon and then link them together as needed for files rather than realloc the individual blocks. I would imagine this would solve the problem.