Originally Posted by
Snafuist
No, I'm suggesting to replace every malloc(<expression>) in your code with malloc(<some constant value that is guaranteed to be large enough to hold whatever you want to store there, e.g. 1MB of memory>).
In my opinion, the hang is caused by a trashed heap due to allocating less memory than is actually needed. In order to give evidence to this assumption, it's a good idea to check whether the hang disappears if you simply allocate enough memory. The problem with a trashed heap is that strange behavior may occur only after the next call to malloc(), which may be perfectly fine in itself (which I suppose fopen()'s malloc() to be).
Greets,
Philip