--- core/src/stored/dev.cc.orig	2020-12-16 08:46:16.000000000 +0100
+++ core/src/stored/dev.cc	2021-01-30 09:41:07.065069696 +0100
@@ -1278,7 +1278,11 @@
   pthread_mutex_destroy(&spool_mutex);
   // RwlDestroy(&lock);
   attached_dcrs.clear();
-  if (device_resource) { device_resource->dev = nullptr; }
+  // drop device_resource link only if it references us
+  if (device_resource && device_resource->dev == this) {
+    Dmsg1(900, "term dev: link from device_resource cleared\n");
+    device_resource->dev = nullptr;
+  }
 }
 
 bool Device::CanStealLock() const
