Fixed the memory leak errors