fix an error that causes memory leakage