fix crash with result iterator when the iterator exists longer than the
result. Reported by Chris Wright