Author: tfaber
Date: Tue Jun 19 23:51:28 2012
New Revision: 56755
URL:
http://svn.reactos.org/svn/reactos?rev=56755&view=rev
Log:
[WS2_32]
- Rewrite completely broken free_hostent and free_servent functions
- Readability improvements to check_hostent and populate_hostent
Modified:
trunk/reactos/dll/win32/ws2_32/misc/ns.c
Modified: trunk/reactos/dll/win32/ws2_32/misc/ns.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/misc/ns.c…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/misc/ns.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/misc/ns.c [iso-8859-1] Tue Jun 19 23:51:28 2012
@@ -518,15 +518,13 @@
sizeof(struct hostent) + MAX_HOSTNAME_LEN + 1);
new_he->h_name = (PCHAR)(new_he + 1);
- new_he->h_aliases = 0;
+ new_he->h_aliases = NULL;
new_he->h_addrtype = 0; // AF_INET
new_he->h_length = 0; // sizeof(in_addr)
new_he->h_addr_list = HeapAlloc(GlobalHeap,
- 0,
+ HEAP_ZERO_MEMORY,
sizeof(char *) * 2);
- RtlZeroMemory(new_he->h_addr_list,
- sizeof(char *) * 2);
*he = new_he;
}
}
@@ -544,7 +542,7 @@
if( !he->h_aliases ) {
he->h_aliases = HeapAlloc(GlobalHeap, 0, sizeof(char *));
- he->h_aliases[0] = 0;
+ he->h_aliases[0] = NULL;
}
he->h_addrtype = AF_INET;
he->h_length = sizeof(IN_ADDR); //sizeof(struct in_addr);
@@ -563,33 +561,33 @@
WS_DbgPrint(MID_TRACE,("he->h_addr_list[0] %x\n",
he->h_addr_list[0]));
RtlCopyMemory(he->h_addr_list[0],
- (char*)&addr.IpAddress,
+ &addr.IpAddress,
sizeof(addr.IpAddress));
- he->h_addr_list[1] = 0;
-}
-
-
-#define HFREE(x) if(x) { HeapFree(GlobalHeap, 0, (x)); x=0; }
+ he->h_addr_list[1] = NULL;
+}
+
void free_hostent(struct hostent *he)
{
- if(he)
- {
- char *next = 0;
- HFREE(he->h_name);
- if(he->h_aliases)
- {
- next = he->h_aliases[0];
- while(next) { HFREE(next); next++; }
- }
- if(he->h_addr_list)
- {
- next = he->h_addr_list[0];
- while(next) { HFREE(next); next++; }
- }
- HFREE(he->h_addr_list);
- HFREE(he->h_aliases);
- HFREE(he);
+ int i;
+
+ if (he)
+ {
+ if (he->h_name)
+ HeapFree(GlobalHeap, 0, he->h_name);
+ if (he->h_aliases)
+ {
+ for (i = 0; he->h_aliases[i]; i++)
+ HeapFree(GlobalHeap, 0, he->h_aliases[i]);
+ HeapFree(GlobalHeap, 0, he->h_aliases);
+ }
+ if (he->h_addr_list)
+ {
+ for (i = 0; he->h_addr_list[i]; i++)
+ HeapFree(GlobalHeap, 0, he->h_addr_list[i]);
+ HeapFree(GlobalHeap, 0, he->h_addr_list);
+ }
+ HeapFree(GlobalHeap, 0, he);
}
}
@@ -672,13 +670,22 @@
void free_servent(struct servent* s)
{
- char* next;
- HFREE(s->s_name);
- next = s->s_aliases[0];
- while(next) { HFREE(next); next++; }
- s->s_port = 0;
- HFREE(s->s_proto);
- HFREE(s);
+ int i;
+
+ if (s)
+ {
+ if (s->s_name)
+ HeapFree(GlobalHeap, 0, s->s_name);
+ if (s->s_aliases)
+ {
+ for (i = 0; s->s_aliases[i]; i++)
+ HeapFree(GlobalHeap, 0, s->s_aliases[i]);
+ HeapFree(GlobalHeap, 0, s->s_aliases);
+ }
+ if (s->s_proto)
+ HeapFree(GlobalHeap, 0, s->s_proto);
+ HeapFree(GlobalHeap, 0, s);
+ }
}
/* This function is far from perfect but it works enough */
@@ -1052,7 +1059,7 @@
*
* @unimplemented
*/
-
+
static CHAR *no_aliases = 0;
static PROTOENT protocols[] =
{
@@ -1061,7 +1068,7 @@
{"udp", &no_aliases, IPPROTO_UDP},
{NULL, NULL, 0}
};
-
+
LPPROTOENT
EXPORT
getprotobyname(IN CONST CHAR FAR* name)
@@ -1203,14 +1210,14 @@
WSASetLastError( WSANO_RECOVERY );
return NULL;
}
-
+
/* Scan the services file ...
*
* We will be share the buffer on the lines. If the line does not fit in
* the buffer, then moving it to the beginning of the buffer and read
* the remnants of line from file.
*/
-
+
/* Initial Read */
ReadFile(ServicesFile,
ServiceDBData,
@@ -1219,7 +1226,7 @@
ThisLine = NextLine = ServiceDBData;
EndValid = ServiceDBData + ReadSize;
ServiceDBData[sizeof(ServiceDBData) - 1] = '\0';
-
+
while(ReadSize)
{
for(; *NextLine != '\r' && *NextLine != '\n';
NextLine++)
@@ -1227,7 +1234,7 @@
if(NextLine == EndValid)
{
int LineLen = NextLine - ThisLine;
-
+
if(ThisLine == ServiceDBData)
{
WS_DbgPrint(MIN_TRACE,("Line too long"));
@@ -1236,23 +1243,23 @@
}
memmove(ServiceDBData, ThisLine, LineLen);
-
+
ReadFile(ServicesFile, ServiceDBData + LineLen,
sizeof( ServiceDBData )-1 - LineLen,
&ReadSize, NULL );
-
+
EndValid = ServiceDBData + LineLen + ReadSize;
NextLine = ServiceDBData + LineLen;
ThisLine = ServiceDBData;
-
+
if(!ReadSize) break;
}
}
-
+
*NextLine = '\0';
Comment = strchr( ThisLine, '#' );
if( Comment ) *Comment = '\0'; /* Terminate at comment start */
-
+
if(DecodeServEntFromString(ThisLine,
&ServiceName,
&PortNumberStr,
@@ -1644,7 +1651,7 @@
return WSAEINVAL;
if (nodename == NULL && servname == NULL)
return WSAHOST_NOT_FOUND;
-
+
if (!WSAINITIALIZED)
return WSANOTINITIALISED;
@@ -1681,7 +1688,7 @@
/* Is it an IPv6 address? */
if (strstr(nodename, ":"))
return WSAHOST_NOT_FOUND;
-
+
/* Is it an IPv4 address? */
addr = inet_addr(nodename);
if (addr != INADDR_NONE)
@@ -1720,7 +1727,7 @@
{
/* accept only A records */
if (currdns->wType != DNS_TYPE_A) continue;
-
+
ai = new_addrinfo(ai);
if (ret == NULL)
ret = ai;
@@ -1771,7 +1778,7 @@
if (ret == NULL)
return WSAHOST_NOT_FOUND;
-
+
if (hints && hints->ai_family != PF_UNSPEC && hints->ai_family
!= PF_INET)
{
freeaddrinfo(ret);