Fixed memory leak that was causing infinite loop.