The mTmpWriteBuffer member variable was never actually being allocated
because it was being shadowed by a local variable. This is why the
code never crashed. I've removed the member variable as it was clearly
never used and really confused the code.
We were not freeing the temporary image buffer if the PNG encoding
failed. This probably doesn't happen very often, but it's good to plug
the leak all the same.