Fix a memory leak

When copying a string you need to hold on to the original reference so
you can free it after.
Also free the tableFiles array

While this frees parts of the memory we neglect to free the strings
inside the array. This still needs to be done.