This is a bunch of low hanging coverity fixes, there are a lot more, but some of them are a bit more intricate, and also there seems to be a fair few false positives (or me deluding myself). Dave.