only free if the pointer is not null