Check for null ptr before use