diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 13540c842f..c5db3c7387 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -403,14 +403,17 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) { return } defer os.Remove(tmpfile.Name()) - defer tmpfile.Close() if _, err := io.Copy(tmpfile, r.Body); err != nil && err != io.EOF { utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to write archive to temporary file: %w", err)) + tmpfile.Close() return } - tmpfile.Close() + if err := tmpfile.Close(); err != nil { + utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to close tempfile: %w", err)) + return + } source = tmpfile.Name() }