Check for NULL pointer before dereferencing