Clean up preview images on upload errors (bug 1051854)

Why not use a context manager here?