Fix memory leak and enable valgrind on travis