Fix freeimage segfault with a broken/truncated JPEG.

This weird corner case exposed an issue in how the error handler callback that handles freeimage errors in C is used (see #1037). 

Here, I have moved the freeimage error handler callback function to the module namespace to prevent it being garbage collected. See the following for
more info on this quirk of ctypes:
http://stackoverflow.com/questions/12995925/how-to-prevent-functype-from-being-collected
JohannesBuchner/PyMultiNest#5

This also changes the way FreeImage errors are handled. If an exception is raised in a callback, it will not propagate beyond ctypes internals. Now, we use a callback that sets a global variable to indicate error. We
then check for error and reset the error string to NULL every time the C api is called. This is the only way I can think of that allows us to:
 - Not segfault on freeimage error
 - Pass the freeimage error to the user
 - raise RuntimeError()

I have also added a test of this error. I can try and down-size the attached JPEG while preserving it's buggyness if this is an issue.

Thanks,
Kevin
I have the Ubuntu version, 3.15.4-3
​