avoid dereferencing NULL pointers
don't leak memory