Index: trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c	(revision 15916)
+++ trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c	(revision 15917)
@@ -611,12 +611,14 @@
  * Destroy a device that has been disconnected from the switch.
  *
+ * @return true iff the instance is destroyed, false otherwise
  * @param   pThis               The instance to be destroyed. This is
  *                              no longer valid when this function returns.
  */
-static void vboxNetFltDestroyInstance(PVBOXNETFLTINS pThis)
+static bool vboxNetFltCheckDestroyInstance(PVBOXNETFLTINS pThis)
 {
     PVBOXNETFLTGLOBALS pGlobals = pThis->pGlobals;
     int rc;
-    LogFlow(("vboxNetFltDestroyInstance: pThis=%p (%s)\n", pThis, pThis->szName));
+    uint32_t cRefs = ASMAtomicUoReadU32((uint32_t volatile *)&pThis->cRefs);
+    LogFlow(("vboxNetFltCheckDestroyInstance: pThis=%p (%s)\n", pThis, pThis->szName));
 
     /*
@@ -640,5 +642,11 @@
      */
     rc = RTSemFastMutexRequest(pGlobals->hFastMtx); AssertRC(rc);
-    vboxNetFltSetState(pThis, kVBoxNetFltInsState_Disconnecting);
+    if(cRefs != 0)
+    {
+        Assert(cRefs < UINT32_MAX / 2);
+        RTSemFastMutexRelease(pGlobals->hFastMtx);
+        return false;
+    }
+    vboxNetFltSetState(pThis, kVBoxNetFltInsState_Destroying);
     RTSemFastMutexRelease(pGlobals->hFastMtx);
 
@@ -658,4 +666,5 @@
     pThis->hSpinlock = NIL_RTSPINLOCK;
     RTMemFree(pThis);
+    return true;
 }
 
@@ -707,5 +716,5 @@
     cRefs = ASMAtomicDecU32(&pThis->cRefs);
     if (!cRefs)
-        vboxNetFltDestroyInstance(pThis);
+        vboxNetFltCheckDestroyInstance(pThis);
     else
         Assert(cRefs < UINT32_MAX / 2);
@@ -961,4 +970,5 @@
 DECLHIDDEN(int) vboxNetFltSearchCreateInstance(PVBOXNETFLTGLOBALS pGlobals, const char *pszName, PVBOXNETFLTINS *ppInstance, void * pContext)
 {
+    PINTNETTRUNKIFPORT pIfPort;
     int rc;
 
@@ -967,23 +977,36 @@
 
     *ppInstance = vboxNetFltFindInstanceLocked(pGlobals, pszName);
-    if(!(*ppInstance))
-    {
-        PINTNETTRUNKIFPORT pIfPort;
-
-        RTSemFastMutexRelease(pGlobals->hFastMtx);
-
-        rc = vboxNetFltNewInstance(pGlobals, pszName, NULL, &pIfPort, pContext);
-        if(RT_SUCCESS(rc))
-            *ppInstance =  IFPORT_2_VBOXNETFLTINS(pIfPort);
-        else
-            *ppInstance = NULL;
-    }
+    if(*ppInstance)
+    {
+        VBOXNETFTLINSSTATE enmState = vboxNetFltGetState(*ppInstance);
+        if(enmState != kVBoxNetFltInsState_Destroying && enmState != kVBoxNetFltInsState_Destroyed)
+        {
+            vboxNetFltRetain(*ppInstance, false);
+            RTSemFastMutexRelease(pGlobals->hFastMtx);
+            return VINF_ALREADY_INITIALIZED;
+        }
+
+        /*wait for the instance to be removed from the list */
+
+        *ppInstance = NULL;
+
+        do
+        {
+            RTSemFastMutexRelease(pGlobals->hFastMtx);
+
+            RTSemEventWait(pGlobals->hTimerEvent, 2);
+
+            rc = RTSemFastMutexRequest(pGlobals->hFastMtx);
+            AssertRCReturn(rc, rc);
+        } while(vboxNetFltFindInstanceLocked(pGlobals, pszName));
+    }
+
+    RTSemFastMutexRelease(pGlobals->hFastMtx);
+
+    rc = vboxNetFltNewInstance(pGlobals, pszName, NULL, &pIfPort, pContext);
+    if(RT_SUCCESS(rc))
+        *ppInstance =  IFPORT_2_VBOXNETFLTINS(pIfPort);
     else
-    {
-        RTSemFastMutexRelease(pGlobals->hFastMtx);
-        rc = VINF_ALREADY_INITIALIZED;
-    }
-
-
+        *ppInstance = NULL;
 
     return rc;
@@ -1186,4 +1209,10 @@
     RTSemFastMutexDestroy(pGlobals->hFastMtx);
     pGlobals->hFastMtx = NIL_RTSEMFASTMUTEX;
+
+#ifdef VBOXNETFLT_STATIC_CONFIG
+    RTSemEventDestroy(pGlobals->hTimerEvent);
+    pGlobals->hTimerEvent = NIL_RTSEMEVENT;
+#endif
+
 }
 
@@ -1222,11 +1251,22 @@
     if (RT_SUCCESS(rc))
     {
-        pGlobals->pInstanceHead = NULL;
-
-        pGlobals->TrunkFactory.pfnRelease = vboxNetFltFactoryRelease;
-        pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetFltFactoryCreateAndConnect;
-
-        strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetFlt");
-        pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetFltQueryFactoryInterface;
+#ifdef VBOXNETFLT_STATIC_CONFIG
+        rc = RTSemEventCreate(&pGlobals->hTimerEvent);
+        if (RT_SUCCESS(rc))
+        {
+#endif
+            pGlobals->pInstanceHead = NULL;
+
+            pGlobals->TrunkFactory.pfnRelease = vboxNetFltFactoryRelease;
+            pGlobals->TrunkFactory.pfnCreateAndConnect = vboxNetFltFactoryCreateAndConnect;
+
+            strcpy(pGlobals->SupDrvFactory.szName, "VBoxNetFlt");
+            pGlobals->SupDrvFactory.pfnQueryFactoryInterface = vboxNetFltQueryFactoryInterface;
+
+            return rc;
+#ifdef VBOXNETFLT_STATIC_CONFIG
+        }
+        RTSemFastMutexDestroy(pGlobals->hFastMtx);
+#endif
     }
 
Index: trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h	(revision 15916)
+++ trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h	(revision 15917)
@@ -68,4 +68,7 @@
      * Partly for reasons of deadlock avoidance again. */
     kVBoxNetFltInsState_Disconnecting,
+    /** Destroying the instance
+     * Partly for reasons of deadlock avoidance again. */
+    kVBoxNetFltInsState_Destroying,
     /** The instance has been disconnected from both the host and the internal network. */
     kVBoxNetFltInsState_Destroyed,
@@ -248,5 +251,8 @@
     /** The number of current factory references. */
     int32_t volatile cFactoryRefs;
-
+#ifdef VBOXNETFLT_STATIC_CONFIG
+    /* wait timer event */
+    RTSEMEVENT hTimerEvent;
+#endif
     /** The SUPDRV IDC handle (opaque struct). */
     SUPDRVIDCHANDLE SupDrvIDC;
