Prevents crash on WPImageOptimizer

Adds a few extra checks to make sure we don't release NULL objects or
return invalid data.

Fixes #2713
Merge pull request #2715 from wordpress-mobile/issue/2713-fix-image-optimizer-crash

Prevents crash on WPImageOptimizer