Mehehe... found it. *p in the while had to be p.
But do check with valgrind again, some other stuff seems to be going wrong too.