Fix large memory leak with image sources.

Reported-by: Ivan Pullman