Browse code

Windows: Fix reference counting in graphdriver

Signed-off-by: Darren Stahl <darst@microsoft.com>

Darren Stahl authored on 2017/03/21 06:57:07
Showing 1 changed files
... ...
@@ -370,6 +370,9 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
370 370
 	mountPath, err := hcsshim.GetLayerMountPath(d.info, rID)
371 371
 	if err != nil {
372 372
 		d.ctr.Decrement(rID)
373
+		if err := hcsshim.UnprepareLayer(d.info, rID); err != nil {
374
+			logrus.Warnf("Failed to Unprepare %s: %s", id, err)
375
+		}
373 376
 		if err2 := hcsshim.DeactivateLayer(d.info, rID); err2 != nil {
374 377
 			logrus.Warnf("Failed to Deactivate %s: %s", id, err)
375 378
 		}
... ...
@@ -402,9 +405,15 @@ func (d *Driver) Put(id string) error {
402 402
 		return nil
403 403
 	}
404 404
 	d.cacheMu.Lock()
405
+	_, exists := d.cache[rID]
405 406
 	delete(d.cache, rID)
406 407
 	d.cacheMu.Unlock()
407 408
 
409
+	// If the cache was not populated, then the layer was left unprepared and deactivated
410
+	if !exists {
411
+		return nil
412
+	}
413
+
408 414
 	if err := hcsshim.UnprepareLayer(d.info, rID); err != nil {
409 415
 		return err
410 416
 	}