Fix one memory leak and possible buffer overflow