Fix possible leak of a cursor when using iterator on loader.