Fix infinite loop
With bad input this function gets stuck in an infinite loop. The reason is that the lambda capture everything by value.
With bad input this function gets stuck in an infinite loop. The reason is that the lambda capture everything by value.