Fix memory leak caused by concurrent image loads