Initialize variable

CID1257729
Re-order assignments to avoid memory leak

CID1230537
Re-shuffle SetThreadName function to match MSDN documentation
Change loop type
Avoid overflow when calculating number of pixels in an image

CID 1041131, 1041132