Browse code

builder: fix duplicate mount release

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2018/10/23 09:24:20
Showing 1 changed files
... ...
@@ -426,10 +426,11 @@ func (s *snapshotter) Close() error {
426 426
 }
427 427
 
428 428
 type mountable struct {
429
-	mu      sync.Mutex
430
-	mounts  []mount.Mount
431
-	acquire func() ([]mount.Mount, error)
432
-	release func() error
429
+	mu       sync.Mutex
430
+	mounts   []mount.Mount
431
+	acquire  func() ([]mount.Mount, error)
432
+	release  func() error
433
+	refCount int
433 434
 }
434 435
 
435 436
 func (m *mountable) Mount() ([]mount.Mount, error) {
... ...
@@ -437,6 +438,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
437 437
 	defer m.mu.Unlock()
438 438
 
439 439
 	if m.mounts != nil {
440
+		m.refCount++
440 441
 		return m.mounts, nil
441 442
 	}
442 443
 
... ...
@@ -445,6 +447,7 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
445 445
 		return nil, err
446 446
 	}
447 447
 	m.mounts = mounts
448
+	m.refCount = 1
448 449
 
449 450
 	return m.mounts, nil
450 451
 }
... ...
@@ -452,6 +455,13 @@ func (m *mountable) Mount() ([]mount.Mount, error) {
452 452
 func (m *mountable) Release() error {
453 453
 	m.mu.Lock()
454 454
 	defer m.mu.Unlock()
455
+
456
+	if m.refCount > 1 {
457
+		m.refCount--
458
+		return nil
459
+	}
460
+
461
+	m.refCount = 0
455 462
 	if m.release == nil {
456 463
 		return nil
457 464
 	}