Fix infinite loop
Fix memory leak