Fix several leaks in the image loader