From 04c4235e972bc6b32f6fe2323b4cefe404d89cce Mon Sep 17 00:00:00 2001 From: Claudiu Mihail Date: Fri, 27 May 2011 19:37:28 +0000 Subject: [PATCH] [TCPIP] Closing a socket while in listening state (that has not accepted any connections) no longer certainly crashes the system. There's still a tendency to crash the system sometimes, but it's related to possibly not canceling any outstanding IRPs for the listening socket. svn path=/branches/GSoC_2011/TcpIpDriver/; revision=51962 --- lib/drivers/ip/transport/tcp/accept.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/drivers/ip/transport/tcp/accept.c b/lib/drivers/ip/transport/tcp/accept.c index 405a95575be..d5e47cb1ea9 100644 --- a/lib/drivers/ip/transport/tcp/accept.c +++ b/lib/drivers/ip/transport/tcp/accept.c @@ -83,7 +83,8 @@ NTSTATUS TCPListen( PCONNECTION_ENDPOINT Connection, UINT Backlog ) } BOOLEAN TCPAbortListenForSocket( PCONNECTION_ENDPOINT Listener, - PCONNECTION_ENDPOINT Connection ) { + PCONNECTION_ENDPOINT Connection ) +{ PLIST_ENTRY ListEntry; PTDI_BUCKET Bucket; KIRQL OldIrql; @@ -92,18 +93,20 @@ BOOLEAN TCPAbortListenForSocket( PCONNECTION_ENDPOINT Listener, LockObject(Listener, &OldIrql); ListEntry = Listener->ListenRequest.Flink; - while ( ListEntry != &Listener->ListenRequest ) { - Bucket = CONTAINING_RECORD(ListEntry, TDI_BUCKET, Entry); + while ( ListEntry != &Listener->ListenRequest ) + { + Bucket = CONTAINING_RECORD(ListEntry, TDI_BUCKET, Entry); - if( Bucket->AssociatedEndpoint == Connection ) { - DereferenceObject(Bucket->AssociatedEndpoint); - RemoveEntryList( &Bucket->Entry ); - ExFreePoolWithTag( Bucket, TDI_BUCKET_TAG ); - Found = TRUE; - break; - } + if( Bucket->AssociatedEndpoint == Connection ) + { + DereferenceObject(Bucket->AssociatedEndpoint); + RemoveEntryList( &Bucket->Entry ); + ExFreePoolWithTag( Bucket, TDI_BUCKET_TAG ); + Found = TRUE; + break; + } - ListEntry = ListEntry->Flink; + ListEntry = ListEntry->Flink; } UnlockObject(Listener, OldIrql); @@ -131,6 +134,8 @@ NTSTATUS TCPAccept ( PTDI_REQUEST Request, if( Bucket ) { Bucket->AssociatedEndpoint = Connection; + ReferenceObject(Bucket->AssociatedEndpoint); + Bucket->Request.RequestNotifyObject = Complete; Bucket->Request.RequestContext = Context; InsertTailList( &Listener->ListenRequest, &Bucket->Entry );