mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-03 04:13:31 +00:00
[MSAFD]
- merge r52193 and rr52198 [IP] - fix memory leak when closing a connection endpoint svn path=/branches/GSoC_2011/TcpIpDriver/; revision=52388
This commit is contained in:
@@ -401,6 +401,7 @@ WSPCloseSocket(IN SOCKET Handle,
|
||||
HANDLE SockEvent;
|
||||
AFD_DISCONNECT_INFO DisconnectInfo;
|
||||
SOCKET_STATE OldState;
|
||||
LONG LingerWait = -1;
|
||||
|
||||
/* Create the Wait Event */
|
||||
Status = NtCreateEvent(&SockEvent,
|
||||
@@ -453,7 +454,6 @@ WSPCloseSocket(IN SOCKET Handle,
|
||||
/* FIXME: Should we do this on Datagram Sockets too? */
|
||||
if ((OldState == SocketConnected) && (Socket->SharedData.LingerData.l_onoff))
|
||||
{
|
||||
ULONG LingerWait;
|
||||
ULONG SendsInProgress;
|
||||
ULONG SleepWait;
|
||||
|
||||
@@ -477,7 +477,11 @@ WSPCloseSocket(IN SOCKET Handle,
|
||||
|
||||
/* Bail out if no more sends are pending */
|
||||
if (!SendsInProgress)
|
||||
{
|
||||
LingerWait = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have to execute a sleep, so it's kind of like
|
||||
* a block. If the socket is Nonblock, we cannot
|
||||
@@ -502,15 +506,14 @@ WSPCloseSocket(IN SOCKET Handle,
|
||||
Sleep(SleepWait);
|
||||
LingerWait -= SleepWait;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We have reached the timeout or sends are over.
|
||||
* Disconnect if the timeout has been reached.
|
||||
*/
|
||||
if (OldState == SocketConnected)
|
||||
{
|
||||
if (LingerWait <= 0)
|
||||
{
|
||||
DisconnectInfo.Timeout = RtlConvertLongToLargeInteger(0);
|
||||
DisconnectInfo.DisconnectType = AFD_DISCONNECT_ABORT;
|
||||
DisconnectInfo.DisconnectType = LingerWait < 0 ? AFD_DISCONNECT_SEND : AFD_DISCONNECT_ABORT;
|
||||
|
||||
/* Send IOCTL */
|
||||
Status = NtDeviceIoControlFile((HANDLE)Handle,
|
||||
@@ -1564,6 +1567,7 @@ WSPConnect(SOCKET Handle,
|
||||
if (Status != STATUS_SUCCESS)
|
||||
goto notify;
|
||||
|
||||
Socket->SharedData.State = SocketConnected;
|
||||
Socket->TdiConnectionHandle = (HANDLE)IOSB.Information;
|
||||
|
||||
/* Get any pending connect data */
|
||||
@@ -1742,6 +1746,13 @@ WSPGetSockName(IN SOCKET Handle,
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
if (!Name || !NameLength)
|
||||
{
|
||||
NtClose(SockEvent);
|
||||
*lpErrno = WSAEFAULT;
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
/* Allocate a buffer for the address */
|
||||
TdiAddressSize =
|
||||
sizeof(TRANSPORT_ADDRESS) + Socket->SharedData.SizeOfLocalAddress;
|
||||
@@ -1836,6 +1847,20 @@ WSPGetPeerName(IN SOCKET s,
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
if (Socket->SharedData.State != SocketConnected)
|
||||
{
|
||||
NtClose(SockEvent);
|
||||
*lpErrno = WSAENOTCONN;
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
if (!Name || !NameLength)
|
||||
{
|
||||
NtClose(SockEvent);
|
||||
*lpErrno = WSAEFAULT;
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
/* Allocate a buffer for the address */
|
||||
TdiAddressSize = sizeof(TRANSPORT_ADDRESS) + *NameLength;
|
||||
SocketAddress = HeapAlloc(GlobalHeap, 0, TdiAddressSize);
|
||||
|
||||
@@ -388,7 +388,14 @@ WSPRecvFrom(SOCKET Handle,
|
||||
}
|
||||
|
||||
/* Re-enable Async Event */
|
||||
SockReenableAsyncSelectEvent(Socket, FD_READ);
|
||||
if (*ReceiveFlags & MSG_OOB)
|
||||
{
|
||||
SockReenableAsyncSelectEvent(Socket, FD_OOB);
|
||||
}
|
||||
else
|
||||
{
|
||||
SockReenableAsyncSelectEvent(Socket, FD_READ);
|
||||
}
|
||||
|
||||
return MsafdReturnWithErrno ( Status, lpErrno, IOSB->Information, lpNumberOfBytesRead );
|
||||
}
|
||||
@@ -667,8 +674,7 @@ WSPSendTo(SOCKET Handle,
|
||||
HeapFree(GlobalHeap, 0, BindAddress);
|
||||
}
|
||||
|
||||
if (Status != STATUS_PENDING)
|
||||
SockReenableAsyncSelectEvent(Socket, FD_WRITE);
|
||||
SockReenableAsyncSelectEvent(Socket, FD_WRITE);
|
||||
|
||||
return MsafdReturnWithErrno(Status, lpErrno, IOSB->Information, lpNumberOfBytesSent);
|
||||
}
|
||||
|
||||
@@ -204,6 +204,8 @@ TCPAcceptEventHandler(void *arg, struct tcp_pcb *newpcb)
|
||||
UnlockObject(Bucket->AssociatedEndpoint, OldIrql);
|
||||
}
|
||||
|
||||
DereferenceObject(Bucket->AssociatedEndpoint);
|
||||
|
||||
DbgPrint("[IP, TCPAcceptEventHandler] Done!\n");
|
||||
|
||||
CompleteBucket(Connection, Bucket, FALSE);
|
||||
|
||||
Reference in New Issue
Block a user