Fix memory leak bug