fix #267 valgrid errors

fix out of memory access
simplify dump methodi, use new instead of malloc
Merge pull request #439 from psychocoderHPC/fix-valgrindErrors

fix #267 valgrind errors