fixed compile and valgrind errors in linux