Fix potential race condition when setting an in-flight image to undefined.