fix compile issues with gcc
fix valgrind issue