Test pointer for NULL *before* dereferencing it, not immediately after (fix crash...