Fixed a bug caused the potential memory leak.