Merge pull request #96 from thaJeztah/18.09_backport_fix-duplicate-release

[18.09 backport] builder: fix duplicate mount release
Upstream-commit: 5bb36e25baef86d3ac230a2fccc182f2766c3e26
Component: engine
This commit is contained in:
Tibor Vass
2018-11-06 11:22:47 -08:00
committed by GitHub
@@ -426,10 +426,11 @@ func (s *snapshotter) Close() error {
}
type mountable struct {
mu sync.Mutex
mounts []mount.Mount
acquire func() ([]mount.Mount, error)
release func() error
mu sync.Mutex
mounts []mount.Mount
acquire func() ([]mount.Mount, error)
release func() error
refCount int
}
func (m *mountable) Mount() ([]mount.Mount, error) {
@@ -437,6 +438,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
defer m.mu.Unlock()
if m.mounts != nil {
m.refCount++
return m.mounts, nil
}
@@ -445,6 +447,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
return nil, err
}
m.mounts = mounts
m.refCount = 1
return m.mounts, nil
}
@@ -452,6 +455,13 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
func (m *mountable) Release() error {
m.mu.Lock()
defer m.mu.Unlock()
if m.refCount > 1 {
m.refCount--
return nil
}
m.refCount = 0
if m.release == nil {
return nil
}