fixed some missing NULL checks, reported by M Bealby in bug #1110