From: John Hodge Date: Mon, 18 Nov 2013 06:42:41 +0000 (+0800) Subject: Modules/IPStack - Added proper node reference counting to TCP X-Git-Tag: rel0.15~87 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c45520530e695150063209cde6016a367a7926c8;p=tpg%2Facess2.git Modules/IPStack - Added proper node reference counting to TCP --- diff --git a/KernelLand/Modules/IPStack/tcp.c b/KernelLand/Modules/IPStack/tcp.c index 8d954bc9..c10213c9 100644 --- a/KernelLand/Modules/IPStack/tcp.c +++ b/KernelLand/Modules/IPStack/tcp.c @@ -1084,6 +1084,7 @@ tVFS_Node *TCP_Client_Init(tInterface *Interface) conn->LocalPort = -1; conn->RemotePort = -1; + conn->Node.ReferenceCount = 1; conn->Node.ImplPtr = conn; conn->Node.NumACLs = 1; conn->Node.ACLs = &gVFS_ACL_EveryoneRW; @@ -1367,6 +1368,15 @@ void TCP_Client_Close(tVFS_Node *Node) ENTER("pNode", Node); + ASSERT(Node->ReferenceCount != 0); + + if( Node->ReferenceCount > 1 ) { + Node->ReferenceCount --; + LOG("Dereference only"); + LEAVE('-'); + return ; + } + if( conn->State == TCP_ST_CLOSE_WAIT || conn->State == TCP_ST_OPEN ) { packet.SourcePort = htons(conn->LocalPort); @@ -1383,6 +1393,9 @@ void TCP_Client_Close(tVFS_Node *Node) switch( conn->State ) { + case TCP_ST_CLOSED: + Log_Warning("TCP", "Closing connection that was never opened"); + break; case TCP_ST_CLOSE_WAIT: conn->State = TCP_ST_LAST_ACK; break;