Add error checking in case of malloc fails

This was missing from original writeImage implementation.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Unindent "finalise" label in writeImage function

Makes function exit path a bit more readable.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Fix uninitialized variables in writeImage functions

Variables png_ptr, info_ptr and row could be uninitialized when error paths
in writeImage function jump into finalise label.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Remove needless NULL check before free()

free() allows also NULL argument.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
Fix potential fclose(NULL) case in main function

fclose() may not accept NULL pointer so add a pointer check to exit
path of the main function.

Signed-off-by: Jarkko Nikula <jarkko.nikula@bitmer.com>