tmp is NULL when i is 0. tmp is then reused for i > 0.