Correct null check

Correct likely copy and paste mistake, and null check the correct
variable.

Fixes Coverity CID 1213840
Merge pull request #4701 from cg110/CoverityFixes4

Fixes for the obvious bug from this weeks coverity scan.