Index: trunk/src/VBox/Devices/Network/slirp/libalias/alias_db.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/libalias/alias_db.c	(revision 40593)
+++ trunk/src/VBox/Devices/Network/slirp/libalias/alias_db.c	(revision 40621)
@@ -345,4 +345,6 @@
      */
     int     sockfd; /* socket descriptor                   */
+#  else
+    struct socket *pSo;
 # endif
 #endif
@@ -570,5 +572,9 @@
 static int  GetNewPort(struct libalias *, struct alias_link *, int);
 #ifndef NO_USE_SOCKETS
+# ifdef VBOX
+static u_short  GetSocket(struct libalias *, u_short, struct alias_link*, int);
+# else
 static u_short  GetSocket(struct libalias *, u_short, int *, int);
+# endif
 #endif
 static void CleanupAliasData(struct libalias *);
@@ -688,5 +694,5 @@
                 if (GetSocket(la, port_net, &lnk->sockfd, lnk->link_type)) {
 #else
-                if (GetSocket(la, port_net, NULL, lnk->link_type)) {
+                if (GetSocket(la, port_net, lnk, lnk->link_type)) {
 #endif
                     lnk->alias_port = port_net;
@@ -716,5 +722,9 @@
 #ifndef NO_USE_SOCKETS
 static      u_short
+# ifndef VBOX
 GetSocket(struct libalias *la, u_short port_net, int *sockfd, int link_type)
+# else
+GetSocket(struct libalias *la, u_short port_net, struct alias_link *pLnk, int link_type)
+# endif
 {
     int err;
@@ -727,5 +737,4 @@
     struct sockaddr sa_addr;
     socklen_t socklen = sizeof(struct sockaddr);
-    NOREF(sockfd);
 #endif
 
@@ -816,4 +825,6 @@
         }
         LogFunc(("bind called for socket: %R[natsock]\n", so));
+	pLnk->pSo = so;
+	so->so_pvLnk = pLnk;
 #else
         *sockfd = sock;
@@ -970,8 +981,20 @@
 }
 
+#ifdef VBOX
+/**
+ * when slirp delete the link we need inform libalias about it.
+ */
+void slirpDeleteLinkSocket(void *pvLnk)
+{
+	struct alias_link *lnk = (struct alias_link *)pvLnk;
+	lnk->pSo = NULL;
+}
+#endif /* !VBOX */
+
 static void
 DeleteLink(struct alias_link *lnk)
 {
     struct libalias *la = lnk->la;
+    LogFlowFunc(("ENTER: lnk->pSo:%R[natsock]\n", lnk->pSo));
 
     LIBALIAS_LOCK_ASSERT(la);
@@ -1008,5 +1031,13 @@
     }
 # else
-    /* Slirp will close the socket in its own way */
+    if (lnk->pSo) 
+    {
+        la->sockCount--;
+	/* should we be more smart, or it's enough to be 
+	 * narrow-minded and just do sofree here 
+	 */
+	sofree(la->pData, lnk->pSo);
+	lnk->pSo = NULL;
+    }
 # endif
 #endif
@@ -1048,4 +1079,5 @@
         ShowAliasStats(la);
     }
+    LogFlowFuncLeave();
 }
 
@@ -1081,4 +1113,6 @@
 # ifndef VBOX
         lnk->sockfd = -1;
+# else
+	lnk->pSo = NULL;
 # endif
 #endif
Index: trunk/src/VBox/Devices/Network/slirp/socket.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 40593)
+++ trunk/src/VBox/Devices/Network/slirp/socket.c	(revision 40621)
@@ -187,4 +187,7 @@
     else if (so == udp_last_so)
         udp_last_so = &udb;
+    /* libalias notification */
+    if (so->so_pvLnk)
+	slirpDeleteLinkSocket(so->so_pvLnk);
 
     /* check if mbuf haven't been already freed  */
@@ -1224,4 +1227,5 @@
 sofcantrcvmore(struct  socket *so)
 {
+    LogFlowFunc(("ENTER: so:%R[natsock]\n", so));
     if ((so->so_state & SS_NOFDREF) == 0)
     {
@@ -1234,4 +1238,5 @@
     else
         so->so_state |= SS_FCANTRCVMORE;
+    LogFlowFuncLeave();
 }
 
@@ -1239,4 +1244,5 @@
 sofcantsendmore(struct socket *so)
 {
+    LogFlowFunc(("ENTER: so:%R[natsock]\n", so));
     if ((so->so_state & SS_NOFDREF) == 0)
         shutdown(so->s, 1);           /* send FIN to fhost */
@@ -1247,4 +1253,5 @@
     else
         so->so_state |= SS_FCANTSENDMORE;
+    LogFlowFuncLeave();
 }
 
Index: trunk/src/VBox/Devices/Network/slirp/socket.h
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/socket.h	(revision 40593)
+++ trunk/src/VBox/Devices/Network/slirp/socket.h	(revision 40621)
@@ -106,4 +106,6 @@
     /* required for port-forwarding */
     struct libalias *so_la;
+    /* libalias might attach the socket and we want to notify libalias we're freeing it */
+    void *so_pvLnk;
 #ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE
     struct socket *so_cloneOf; /* pointer to master instance */
@@ -111,4 +113,7 @@
 #endif
 };
+
+/* this function inform libalias about socket close */
+void slirpDeleteLinkSocket(void *pvLnk);
 
 #ifdef VBOX_WITH_SLIRP_MT
Index: trunk/src/VBox/Devices/Network/slirp/tcp_subr.c
===================================================================
--- trunk/src/VBox/Devices/Network/slirp/tcp_subr.c	(revision 40593)
+++ trunk/src/VBox/Devices/Network/slirp/tcp_subr.c	(revision 40621)
@@ -355,4 +355,5 @@
 {
     LogFlowFunc(("ENTER: tp = %R[tcpcb793]\n", tp));
+    LogFunc(("tp->t_socket:%R[natsock]\n",tp->t_socket));
 
     switch (tp->t_state)
