Fixed a memory leak identified by valgrind