Fix memory leak and clobbering of image source data.