Fixed memory leak in cleanup detected by valgrind