You're leaking a lot of memory

Don't leak memory in the table. Each iteration allocates memory that's never freed.