Code fixes

Various code fixes, mostly discovered by MSVC code static analyzer .
It looks like the comment can be removed?  Though by the looks there's no check for pixelbuf NULL (I guess it throws?)