Iterative segfault... leaky memories