Fix for memory leak

Here are two commits that try to fix the memory leak problem. The first commit seems pretty safe, the second one is only a partial solution as it frees the tableFiles array but not the actual contents of the array.
@bertfrees can you look at this?