Check correct variable for NULL

Issue discovered by Coverity scan, CID 43163. This should fix CID 43172 as a
side-effect as well.