Index: dll/win32/msafd/misc/dllmain.c =================================================================== --- dll/win32/msafd/misc/dllmain.c (revision 74470) +++ dll/win32/msafd/misc/dllmain.c (working copy) @@ -677,9 +677,6 @@ if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } - /* Set the state to close */ - OldState = Socket->SharedData->State; - Socket->SharedData->State = SocketClosed; /* Decrement reference count on SharedData */ References = InterlockedDecrement(&Socket->SharedData->RefCount); @@ -686,6 +683,10 @@ if (References) goto ok; + /* Set the state to close */ + OldState = Socket->SharedData->State; + Socket->SharedData->State = SocketClosed; + /* If SO_LINGER is ON and the Socket is connected, we need to disconnect */ /* FIXME: Should we do this on Datagram Sockets too? */ if ((OldState == SocketConnected) && (Socket->SharedData->LingerData.l_onoff))