Merge pull request #36728 from darrenstahlmsft/LayerLeak

Fix Windows layer leak when write fails
This commit is contained in:
Anusha Ragunathan 2018-04-04 19:05:59 -07:00 committed by GitHub
commit a8260058e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -779,7 +779,7 @@ func writeLayerReexec() {
}
// writeLayer writes a layer from a tar file.
func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ...string) (int64, error) {
func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ...string) (size int64, retErr error) {
err := winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege})
if err != nil {
return 0, err
@ -804,17 +804,17 @@ func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ..
return 0, err
}
size, err := writeLayerFromTar(layerData, w, filepath.Join(home, id))
if err != nil {
return 0, err
}
defer func() {
if err := w.Close(); err != nil {
// This error should not be discarded as a failure here
// could result in an invalid layer on disk
if retErr == nil {
retErr = err
}
}
}()
err = w.Close()
if err != nil {
return 0, err
}
return size, nil
return writeLayerFromTar(layerData, w, filepath.Join(home, id))
}
// resolveID computes the layerID information based on the given id.