fix bug in memory leaks