Bugzilla bug 226686: we need to close the new socket if _MD_FAST_ACCEPT or NSPR_4_4_BRANCH
authorwchang0222%aol.com
Tue, 25 Nov 2003 00:44:57 +0000
branchNSPR_4_4_BRANCH
changeset 2983 e4a540feaa813fc56b2ca86cac89a0c47f29ed13
parent 2982 bc4343a7558bd650afbd7091d07e7b3ed682430a
child 2984 f6699062a617412e5e20f6dbc15110bfd294d858
child 3118 e325b2f7a2491d3a2638820d0cdd6b543932a76a
push idunknown
push userunknown
push dateunknown
bugs226686
Bugzilla bug 226686: we need to close the new socket if _MD_FAST_ACCEPT or _MD_FAST_ACCEPT_READ fails. Tag: NSPR_4_4_BRANCH
pr/src/md/windows/ntio.c
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -1327,16 +1327,17 @@ PRInt32
 	if (_native_threads_only)
 		me->md.overlapped.overlapped.hEvent = me->md.thr_event;
 
     _PR_THREAD_LOCK(me);
 	if (_PR_PENDING_INTERRUPT(me)) {
 		me->flags &= ~_PR_INTERRUPT;
 		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
     	_PR_THREAD_UNLOCK(me);
+		closesocket(accept_sock);
 		return -1;
 	}
     me->io_pending = PR_TRUE;
     me->state = _PR_IO_WAIT;
     _PR_THREAD_UNLOCK(me);
     me->io_fd = osfd;
 
     rv = AcceptEx((SOCKET)osfd,
@@ -1345,16 +1346,17 @@ PRInt32
                   0,
                   INET_ADDR_PADDED,
                   INET_ADDR_PADDED,
                   &bytes,
                   &(me->md.overlapped.overlapped));
 
     if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING))  {
         /* Argh! The IO failed */
+		closesocket(accept_sock);
 		_PR_THREAD_LOCK(me);
 		me->io_pending = PR_FALSE;
 		me->state = _PR_RUNNING;
 		if (_PR_PENDING_INTERRUPT(me)) {
 			me->flags &= ~_PR_INTERRUPT;
 			PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
 			_PR_THREAD_UNLOCK(me);
 			return -1;
@@ -1364,32 +1366,35 @@ PRInt32
 		_PR_MD_MAP_ACCEPTEX_ERROR(err);
         return -1;
     }
 
     if (_native_threads_only && rv) {
         _native_thread_io_nowait(me, rv, bytes);
     } else if (_NT_IO_WAIT(me, timeout) == PR_FAILURE) {
         PR_ASSERT(0);
+        closesocket(accept_sock);
         return -1;
     }
 
     PR_ASSERT(me->io_pending == PR_FALSE || me->io_suspended == PR_TRUE);
 
     if (me->io_suspended) {
+        closesocket(accept_sock);
         if (_PR_PENDING_INTERRUPT(me)) {
             me->flags &= ~_PR_INTERRUPT;
             PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
         } else {
             PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
         }
         return -1;
     }
 
     if (me->md.blocked_io_status == 0) {
+		closesocket(accept_sock);
 		_PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
         return -1;
     }
 
     if (!fast)
         _PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)accept_sock, (SOCKET)osfd);
 
     /* IO is done */
@@ -1445,16 +1450,17 @@ PRInt32
 	if (_native_threads_only)
 		me->md.overlapped.overlapped.hEvent = me->md.thr_event;
 
     _PR_THREAD_LOCK(me);
 	if (_PR_PENDING_INTERRUPT(me)) {
 		me->flags &= ~_PR_INTERRUPT;
 		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
     	_PR_THREAD_UNLOCK(me);
+		closesocket(*newSock);
 		return -1;
 	}
     me->io_pending = PR_TRUE;
     me->state = _PR_IO_WAIT;
     _PR_THREAD_UNLOCK(me);
     me->io_fd = sock;
 
     rv = AcceptEx((SOCKET)sock,
@@ -1462,16 +1468,17 @@ PRInt32
                   buf,
                   amount,
                   INET_ADDR_PADDED,
                   INET_ADDR_PADDED,
                   &bytes,
                   &(me->md.overlapped.overlapped));
 
     if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING)) {
+		closesocket(*newSock);
 		_PR_THREAD_LOCK(me);
 		me->io_pending = PR_FALSE;
 		me->state = _PR_RUNNING;
 		if (_PR_PENDING_INTERRUPT(me)) {
 			me->flags &= ~_PR_INTERRUPT;
 			PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
 			_PR_THREAD_UNLOCK(me);
 			return -1;
@@ -1481,16 +1488,17 @@ PRInt32
 		_PR_MD_MAP_ACCEPTEX_ERROR(err);
         return -1;
     }
 
     if (_native_threads_only && rv) {
         _native_thread_io_nowait(me, rv, bytes);
     } else if (_NT_IO_WAIT(me, timeout) == PR_FAILURE) {
         PR_ASSERT(0);
+        closesocket(*newSock);
         return -1;
     }
 
 retry:
     if (me->io_suspended) {
         PRInt32 err;
         INT seconds;
         INT bytes = sizeof(seconds);
@@ -1510,27 +1518,31 @@ retry:
             else 
                 isConnected = PR_TRUE;
 
             if (!isConnected) {
                 if (madeCallback == PR_FALSE && callback)
                     callback(callbackArg);
                 madeCallback = PR_TRUE;
                 me->state = _PR_IO_WAIT;
-                if (_NT_ResumeIO(me, timeout) == PR_FAILURE)
+                if (_NT_ResumeIO(me, timeout) == PR_FAILURE) {
+                    closesocket(*newSock);
                     return -1;
+                }
                 goto retry;
             }
 
             if (elapsed < timeout) {
                 /* Socket is connected but time not elapsed, RESUME IO */
                 timeout -= elapsed;
                 me->state = _PR_IO_WAIT;
-                if (_NT_ResumeIO(me, timeout) == PR_FAILURE)
+                if (_NT_ResumeIO(me, timeout) == PR_FAILURE) {
+                    closesocket(*newSock);
                     return -1;
+                }
                 goto retry;
             }
         } else {
             /*  What to do here? Assume socket not open?*/
             PR_ASSERT(0);
             isConnected = PR_FALSE;
         }
 
@@ -1547,16 +1559,17 @@ retry:
         me->io_suspended = PR_FALSE;
         if (_PR_PENDING_INTERRUPT(me)) {
             me->flags &= ~_PR_INTERRUPT;
             PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
         } else {
             PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
         }
         me->state = _PR_RUNNING;
+        closesocket(*newSock);
         return -1;
     }
 
     PR_ASSERT(me->io_pending == PR_FALSE);
     PR_ASSERT(me->io_suspended == PR_FALSE);
     PR_ASSERT(me->md.thr_bound_cpu == NULL);
 
     if (me->md.blocked_io_status == 0) {