Handle freeing objects in a list with complex data types

Changes the freelist function to take a function parameter that 
knows how to deallocate complex objects in the list, since using 
`free` on data types that require a special deallocation function 
is uncertain.