Index: trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c	(revision 23280)
+++ trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c	(revision 23281)
@@ -384,5 +384,5 @@
 
 /** Goes along with the instance to determine type of stream being opened/created. */
-VBOXNETFLTSTREAMTYPE volatile g_VBoxNetFltSolarisStreamType;
+VBOXNETFLTSTREAMTYPE volatile g_VBoxNetFltSolarisStreamType = kUndefined;
 
 #ifdef VBOXNETFLT_SOLARIS_IPV6_POLLING
@@ -664,7 +664,10 @@
      * Check VirtualBox stream type.
      */
-    if (g_VBoxNetFltSolarisStreamType == kUndefined)
-    {
-        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed due to undefined VirtualBox open mode.\n"));
+    if (   g_VBoxNetFltSolarisStreamType != kPromiscStream
+        && g_VBoxNetFltSolarisStreamType != kArpStream
+        && g_VBoxNetFltSolarisStreamType != kIp6Stream
+        && g_VBoxNetFltSolarisStreamType != kIp4Stream)
+    {
+        LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed due to undefined VirtualBox open mode. Type=%d\n", g_VBoxNetFltSolarisStreamType));
         RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
         return ENOENT;
@@ -741,6 +744,8 @@
         default:    /* Heh. */
         {
-            AssertRelease(pStream->Type);
-            break;
+            LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen huh!? Invalid stream type %d\n", pStream->Type));
+            RTMemFree(pStream);
+            RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
+            return EINVAL;
         }
     }
@@ -754,4 +759,9 @@
     pStream->pNext = *ppPrevStream;
     *ppPrevStream = pStream;
+
+    /*
+     * Increment IntNet reference count for this stream.
+     */
+    vboxNetFltRetain(pThis, false /* fBusy */);
 
     /*
@@ -841,5 +851,4 @@
     {
         LogRel((DEVICE_NAME ":VBoxNetFltSolarisModClose failed to get stream.\n"));
-        vboxNetFltRelease(pStream->pThis, false /* fBusy */);
         RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
         return ENXIO;
@@ -914,5 +923,9 @@
     }
 
+    /*
+     * Decrement IntNet reference count for this stream.
+     */
     vboxNetFltRelease(pStream->pThis, false /* fBusy */);
+
     RTMemFree(pStream);
     pQueue->q_ptr = NULL;
@@ -1753,5 +1766,5 @@
             }
 
-            LogRel((DEVICE_NAME ":vboxNetFltSolarisDetermineModPos: failed to find %s in the host stack.\n"));
+            LogRel((DEVICE_NAME ":vboxNetFltSolarisDetermineModPos: failed to find %s in the host stack.\n", DEVICE_NAME));
         }
         else
@@ -1916,6 +1929,4 @@
 {
     LogFlow((DEVICE_NAME ":vboxNetFltSolarisCloseStream pThis=%p\n"));
-
-    vboxNetFltRetain(pThis, false /* fBusy */);
 
     ldi_close(pThis->u.s.hIface, FREAD | FWRITE, kcred);
@@ -2047,6 +2058,4 @@
                                  * Inject/Eject from the host IP stack.
                                  */
-                                if (!fAttach)
-                                    vboxNetFltRetain(pThis, false /* fBusy */);
 
                                 /*
@@ -2066,7 +2075,4 @@
                                 if (!rc)
                                 {
-                                    if (!fAttach)
-                                        vboxNetFltRetain(pThis, false /* fBusy */);
-
                                     /*
                                      * Inject/Eject from the host ARP stack.
@@ -2127,7 +2133,4 @@
 
                                     vboxNetFltSolarisRelinkIp4(pUdp4VNode, &Ip4Interface, Ip4MuxFd, ArpMuxFd);
-
-                                    if (!fAttach)
-                                        vboxNetFltRelease(pThis, false /* fBusy */);
                                 }
                                 else
@@ -2139,7 +2142,4 @@
                                 g_VBoxNetFltSolarisInstance = NULL;
                                 g_VBoxNetFltSolarisStreamType = kUndefined;
-
-                                if (!fAttach)
-                                    vboxNetFltRelease(pThis, false /* fBusy */);
                             }
                             else
@@ -2279,7 +2279,4 @@
                             if (RT_SUCCESS(rc))
                             {
-                                if (!fAttach)
-                                    vboxNetFltRetain(pThis, false /* fBusy */);
-
                                 /*
                                  * Set global data which will be grabbed by ModOpen.
@@ -2335,6 +2332,4 @@
                                     LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachIp6: failed to %s the IP stack. rc=%d\n",
                                             fAttach ? "inject into" : "eject from", rc));
-                                    if (!fAttach)
-                                        vboxNetFltRelease(pThis, false /* fBusy */);
                                 }
                             }
@@ -2477,5 +2472,7 @@
     ASMAtomicWriteBool(&pThis->fDisconnectedFromHost, true);
     vboxNetFltSolarisCloseStream(pThis);
-    int rc = vboxNetFltSolarisAttachIp4(pThis, false /* fAttach */);
+    int rc = VINF_SUCCESS;
+    if (pThis->u.s.pvIp4Stream)
+        rc = vboxNetFltSolarisAttachIp4(pThis, false /* fAttach */);
     if (pThis->u.s.pvIp6Stream)
         rc = vboxNetFltSolarisAttachIp6(pThis, false /* fAttach */);
