Fix a memory leaks problem