png error handling is incorrect/error message is misleading
Created by: siebenkopf
I have lately seen errors (Exceptions) while reading png images. The error message I got was
PNG: error while setting error handling (function setjmp(png_jmpbuf(()))
which are issued somewhere here: https://github.com/bioidiap/bob.io.image/blob/master/bob/io/image/cpp/png.cpp#L235
However, when reading about the setjmp
function, this function is a bit twisted. It returns 0 while setting the function, while non-zero when the function is actually called caused by another error. I have read a bit more about error handling using libpng, (e.g., how to set up a proper error handler), but I haven't yet found a good solution on how to raise C++ exceptions without leaving memory leaks.
Anyways, currently there is no way to know, why libpng raised the error. The given error message does not explain anything. There seems to be a better way (where we actually get a pointer to the error message):
http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-5
but I don't see, how we can exit cleanly form user_error_fn
without leaving the memory allocated here:
https://github.com/bioidiap/bob.io.image/blob/master/bob/io/image/cpp/png.cpp#L222
and cleaned here:
https://github.com/bioidiap/bob.io.image/blob/master/bob/io/image/cpp/png.cpp#L234
leaking.
Any idea?