Fix a bug which may cause a serious memory leak