fix a bug in memory leak