fixed a bug that caused memory leak when free