Avoid freeing NULL pointers