Fixed a memory leak and an incorrect debug message