Author: arty
Date: Mon Aug 21 07:59:02 2006
New Revision: 23638
URL:
http://svn.reactos.org/svn/reactos?rev=23638&view=rev
Log:
- Fixed timeout calculation.
- Fixed a couple of leaks.
Modified:
trunk/reactos/dll/win32/msafd/misc/dllmain.c
Modified: trunk/reactos/dll/win32/msafd/misc/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msafd/misc/dllma…
==============================================================================
--- trunk/reactos/dll/win32/msafd/misc/dllmain.c (original)
+++ trunk/reactos/dll/win32/msafd/misc/dllmain.c Mon Aug 21 07:59:02 2006
@@ -597,11 +597,7 @@
ULONG i, j = 0, x;
HANDLE SockEvent;
BOOL HandleCounted;
-
- Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
- NULL, 1, FALSE );
-
- if( !NT_SUCCESS(Status) ) return SOCKET_ERROR;
+ LARGE_INTEGER Timeout;
/* Find out how many sockets we have, and how large the buffer needs
* to be */
@@ -613,30 +609,54 @@
if( HandleCount < 0 || nfds != 0 ) HandleCount = nfds * 3;
- PollBufferSize = sizeof(*PollInfo) +
- (HandleCount * sizeof(AFD_HANDLE));
+ PollBufferSize = sizeof(*PollInfo) + (HandleCount * sizeof(AFD_HANDLE));
AFD_DbgPrint(MID_TRACE,("HandleCount: %d BufferSize: %d\n",
HandleCount, PollBufferSize));
+ /* Convert Timeout to NT Format */
+ if (timeout == NULL) {
+ Timeout.u.LowPart = -1;
+ Timeout.u.HighPart = 0x7FFFFFFF;
+ AFD_DbgPrint(MAX_TRACE,("Infinite timeout\n"));
+ } else {
+ Timeout = RtlEnlargedIntegerMultiply
+ ((timeout->tv_sec * 1000) + (timeout->tv_usec / 1000), -10000);
+ /* Negative timeouts are illegal. Since the kernel represents an
+ * incremental timeout as a negative number, we check for a positive
+ * result.
+ */
+ if (Timeout.QuadPart > 0) {
+ if (lpErrno) *lpErrno = WSAEINVAL;
+ return SOCKET_ERROR;
+ }
+ AFD_DbgPrint(MAX_TRACE,("Timeout: Orig %d.%06d kernel %d\n",
+ timeout->tv_sec, timeout->tv_usec,
+ Timeout.u.LowPart));
+ }
+
+ Status = NtCreateEvent( &SockEvent, GENERIC_READ | GENERIC_WRITE,
+ NULL, 1, FALSE );
+
+ if( !NT_SUCCESS(Status) ) return SOCKET_ERROR;
+
/* Allocate */
PollBuffer = HeapAlloc(GlobalHeap, 0, PollBufferSize);
+
+ if (!PollBuffer) {
+ if (*lpErrno) *lpErrno = WSAEFAULT;
+ NtClose(SockEvent);
+ return SOCKET_ERROR;
+ }
+
PollInfo = (PAFD_POLL_INFO)PollBuffer;
-
+
RtlZeroMemory( PollInfo, PollBufferSize );
- /* Convert Timeout to NT Format */
- if (timeout == NULL) {
- PollInfo->Timeout.u.LowPart = -1;
- PollInfo->Timeout.u.HighPart = 0x7FFFFFFF;
- } else {
- PollInfo->Timeout = RtlEnlargedIntegerMultiply
- ((timeout->tv_sec * 1000) + timeout->tv_usec, -10000);
- }
-
/* Number of handles for AFD to Check */
PollInfo->HandleCount = HandleCount;
PollInfo->Exclusive = FALSE;
+ PollInfo->Timeout = Timeout;
if (readfds != NULL) {
for (i = 0; i < readfds->fd_count; i++, j++) {
@@ -734,6 +754,7 @@
}
}
+ HeapFree( GlobalHeap, 0, PollBuffer );
NtClose( SockEvent );
AFD_DbgPrint(MID_TRACE,("lpErrno = %x\n", lpErrno));