- use Heap functions rather than libc for mem allocation

- document a bunch of functions
This commit is contained in:
Juan Lang 2004-12-13 13:21:39 +00:00 committed by Alexandre Julliard
parent 53b71e464a
commit 76d8779c6f
5 changed files with 217 additions and 169 deletions

View File

@ -33,7 +33,6 @@
* than my current mess would probably be better.
* FIXME:
* - I don't support IPv6 addresses here, since SIOCGIFCONF can't return them
* - the memory interface uses malloc/free; it should be using HeapAlloc instead
*
* There are three implemened methods for determining the MAC address of an
* interface:
@ -154,9 +153,9 @@ void interfaceMapFree(void)
{
DeleteCriticalSection(&mapCS);
if (gNonLoopbackInterfaceMap)
free(gNonLoopbackInterfaceMap);
HeapFree(GetProcessHeap(), 0, gNonLoopbackInterfaceMap);
if (gLoopbackInterfaceMap)
free(gLoopbackInterfaceMap);
HeapFree(GetProcessHeap(), 0, gLoopbackInterfaceMap);
}
/* Sizes the passed-in map to have enough space for numInterfaces interfaces.
@ -168,14 +167,16 @@ static InterfaceNameMap *sizeMap(InterfaceNameMap *map, DWORD numInterfaces)
{
if (!map) {
numInterfaces = max(numInterfaces, INITIAL_INTERFACES_ASSUMED);
map = (InterfaceNameMap *)calloc(1, sizeof(InterfaceNameMap) +
map = (InterfaceNameMap *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(InterfaceNameMap) +
(numInterfaces - 1) * sizeof(InterfaceNameMapEntry));
if (map)
map->numAllocated = numInterfaces;
}
else {
if (map->numAllocated < numInterfaces) {
map = (InterfaceNameMap *)realloc(map, sizeof(InterfaceNameMap) +
map = (InterfaceNameMap *)HeapReAlloc(GetProcessHeap(), 0, map,
sizeof(InterfaceNameMap) +
(numInterfaces - 1) * sizeof(InterfaceNameMapEntry));
if (map)
memset(&map->table[map->numAllocated], 0,
@ -321,9 +322,9 @@ static void enumerateInterfaces(void)
else
guessedNumInterfaces *= 2;
if (ifc.ifc_buf)
free(ifc.ifc_buf);
HeapFree(GetProcessHeap(), 0, ifc.ifc_buf);
ifc.ifc_len = sizeof(struct ifreq) * guessedNumInterfaces;
ifc.ifc_buf = (char *)malloc(ifc.ifc_len);
ifc.ifc_buf = (char *)HeapAlloc(GetProcessHeap(), 0, ifc.ifc_len);
ret = ioctl(fd, SIOCGIFCONF, &ifc);
} while (ret == 0 &&
ifc.ifc_len == (sizeof(struct ifreq) * guessedNumInterfaces));
@ -336,7 +337,7 @@ static void enumerateInterfaces(void)
}
if (ifc.ifc_buf)
free(ifc.ifc_buf);
HeapFree(GetProcessHeap(), 0, ifc.ifc_buf);
close(fd);
}
}
@ -432,7 +433,7 @@ InterfaceIndexTable *getInterfaceIndexTable(void)
EnterCriticalSection(&mapCS);
numInterfaces = getNumInterfaces();
ret = (InterfaceIndexTable *)calloc(1,
ret = (InterfaceIndexTable *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(InterfaceIndexTable) + (numInterfaces - 1) * sizeof(DWORD));
if (ret) {
ret->numAllocated = numInterfaces;
@ -450,7 +451,7 @@ InterfaceIndexTable *getNonLoopbackInterfaceIndexTable(void)
EnterCriticalSection(&mapCS);
numInterfaces = getNumNonLoopbackInterfaces();
ret = (InterfaceIndexTable *)calloc(1,
ret = (InterfaceIndexTable *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(InterfaceIndexTable) + (numInterfaces - 1) * sizeof(DWORD));
if (ret) {
ret->numAllocated = numInterfaces;
@ -719,12 +720,12 @@ DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr,
if (sysctl(mib, 6, NULL, &mibLen, NULL, 0) < 0)
return ERROR_NO_MORE_FILES;
buf = (u_char *)malloc(mibLen);
buf = (u_char *)HeapAlloc(GetProcessHeap(), 0, mibLen);
if (!buf)
return ERROR_NOT_ENOUGH_MEMORY;
if (sysctl(mib, 6, buf, &mibLen, NULL, 0) < 0) {
free(buf);
HeapFree(GetProcessHeap(), 0, buf);
return ERROR_NO_MORE_FILES;
}
@ -786,7 +787,7 @@ DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr,
ret = NO_ERROR;
}
}
free(buf);
HeapFree(GetProcessHeap(), 0, buf);
return ret;
}
#endif

View File

@ -62,7 +62,7 @@ typedef struct _InterfaceIndexTable {
} InterfaceIndexTable;
/* Returns a table with all known interface indexes, or NULL if one could not
* be allocated. free() the returned table.
* be allocated. HeapFree() the returned table.
*/
InterfaceIndexTable *getInterfaceIndexTable(void);

File diff suppressed because it is too large Load Diff

View File

@ -565,8 +565,8 @@ RouteTable *getRouteTable(void)
DWORD numRoutes = getNumRoutes();
RouteTable *ret;
ret = (RouteTable *)calloc(1, sizeof(RouteTable) +
(numRoutes - 1) * sizeof(RouteEntry));
ret = (RouteTable *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(RouteTable) + (numRoutes - 1) * sizeof(RouteEntry));
if (ret) {
FILE *fp;
@ -638,8 +638,8 @@ PMIB_IPNETTABLE getArpTable(void)
DWORD numEntries = getNumArpEntries();
PMIB_IPNETTABLE ret;
ret = (PMIB_IPNETTABLE)calloc(1, sizeof(MIB_IPNETTABLE) +
(numEntries - 1) * sizeof(MIB_IPNETROW));
ret = (PMIB_IPNETTABLE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MIB_IPNETTABLE) + (numEntries - 1) * sizeof(MIB_IPNETROW));
if (ret) {
FILE *fp;
@ -716,8 +716,8 @@ PMIB_UDPTABLE getUdpTable(void)
DWORD numEntries = getNumUdpEntries();
PMIB_UDPTABLE ret;
ret = (PMIB_UDPTABLE)calloc(1, sizeof(MIB_UDPTABLE) +
(numEntries - 1) * sizeof(MIB_UDPROW));
ret = (PMIB_UDPTABLE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW));
if (ret) {
FILE *fp;
@ -768,8 +768,8 @@ PMIB_TCPTABLE getTcpTable(void)
DWORD numEntries = getNumTcpEntries();
PMIB_TCPTABLE ret;
ret = (PMIB_TCPTABLE)calloc(1, sizeof(MIB_TCPTABLE) +
(numEntries - 1) * sizeof(MIB_TCPROW));
ret = (PMIB_TCPTABLE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW));
if (ret) {
FILE *fp;

View File

@ -74,7 +74,7 @@ typedef struct _RouteTable {
} RouteTable;
/* Allocates and returns to you the route table, or NULL if it can't allocate
* enough memory. free() the returned table.
* enough memory. HeapFree() the returned table.
*/
RouteTable *getRouteTable(void);
@ -82,7 +82,7 @@ RouteTable *getRouteTable(void);
DWORD getNumArpEntries(void);
/* Allocates and returns to you the arp table, or NULL if it can't allocate
* enough memory. free() the returned table.
* enough memory. HeapFree() the returned table.
*/
PMIB_IPNETTABLE getArpTable(void);
@ -90,7 +90,7 @@ PMIB_IPNETTABLE getArpTable(void);
DWORD getNumUdpEntries(void);
/* Allocates and returns to you the UDP state table, or NULL if it can't
* allocate enough memory. free() the returned table.
* allocate enough memory. HeapFree() the returned table.
*/
PMIB_UDPTABLE getUdpTable(void);
@ -98,7 +98,7 @@ PMIB_UDPTABLE getUdpTable(void);
DWORD getNumTcpEntries(void);
/* Allocates and returns to you the TCP state table, or NULL if it can't
* allocate enough memory. free() the returned table.
* allocate enough memory. HeapFree() the returned table.
*/
PMIB_TCPTABLE getTcpTable(void);