fixed memory leak on length