You are probably overrunning beyond the allocated mem somewhere. then the underlying sw doesn't pick up on it until you call malloc
There may be a guard value clobbered that is being caught by malloc.
edit...added this for bounds checking help
http://www.lrde.epita.fr/~akim/ccmp/doc/bounds-checking.html