OK, I think I found my mistake. The key is in lines.c/writeLines(). The growth condition is capacity < count + 1, but my count increases like 1, 3, 5, 7. When it reaches 7, the array should grow because we've reached the end of the array. Therefore, it should be "<=" instead of "<".