If you have something which contains pointers, you should have a destructor function for it, which itself should check if the pointer is not NULL before attempting to free any fields.
That's certainly one way to do it if you're writing all the code.
That's certainly one way to do it if you're writing all the code.