Do not free NULL

When tableFiles is NULL the macro tried to free it anyway. Change the
macro into a function and test for NULL before freeing.

This fixes a segfault in the tests.