fix memleak checked by valgrind