Fix some coverity scan issues

I thought I'd take a look at the current coverity scan issues, and saw a few easy/low hanging ones to fix.

Mainly null protection, but one resource leak fix.

Would be quite nice to get a more up-to-date build scanned, I'll raise on the forums.