Author: weiden
Date: Sun Dec 30 00:40:31 2007
New Revision: 31496
URL:
http://svn.reactos.org/svn/reactos?rev=31496&view=rev
Log:
Fix some handle leaks and warnings
Modified:
trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c
trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c
trunk/reactos/dll/win32/iphlpapi/route_reactos.c
Modified: trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/ifenum_…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c (original)
+++ trunk/reactos/dll/win32/iphlpapi/ifenum_reactos.c Sun Dec 30 00:40:31 2007
@@ -99,6 +99,7 @@
if (!NT_SUCCESS(status)) {
ERR("openTcpFile for <%wZ> failed: 0x%lx\n", &fileName,
status);
+ *tcpFile = INVALID_HANDLE_VALUE;
}
return status;
@@ -106,7 +107,8 @@
void closeTcpFile( HANDLE h ) {
TRACE("called.\n");
- NtClose( h );
+ ASSERT(h != INVALID_HANDLE_VALUE);
+ ZwClose( h );
}
/* A generic thing-getting function which interacts in the right way with
@@ -462,6 +464,7 @@
if( !NT_SUCCESS(status) ) {
WARN("getNumInterfaces: failed %08x\n", status );
+ closeTcpFile( tcpFile );
return 0;
}
@@ -550,7 +553,7 @@
if( NT_SUCCESS(status) )
for( i = 0; i < numInterfaces; i++ ) {
- if( !strcmp(ifInfo[i].if_info.ent.if_descr, name) ) {
+ if( !strcmp((PCHAR)ifInfo[i].if_info.ent.if_descr, name) ) {
memcpy( info, &ifInfo[i], sizeof(*info) );
break;
}
@@ -575,14 +578,14 @@
status = getInterfaceInfoByIndex( tcpFile, index, &ifInfo );
if( NT_SUCCESS(status) ) {
- adapter_name = ifInfo.if_info.ent.if_descr;
+ adapter_name = (char *)ifInfo.if_info.ent.if_descr;
interfaceName = HeapAlloc( GetProcessHeap(), 0,
strlen(adapter_name) + 1 );
strcpy( interfaceName, adapter_name );
-
- closeTcpFile( tcpFile );
- }
+ }
+
+ closeTcpFile( tcpFile );
}
return interfaceName;
@@ -603,8 +606,9 @@
if( NT_SUCCESS(status) ) {
*index = ifInfo.if_info.ent.if_index;
- closeTcpFile( tcpFile );
- }
+ }
+
+ closeTcpFile( tcpFile );
}
return status;
@@ -688,7 +692,7 @@
DWORD getAddrByIndexOrName( char *name, DWORD index, IPHLPAddrType addrType ) {
IFInfo ifInfo;
- HANDLE tcpFile = INVALID_HANDLE_VALUE;
+ HANDLE tcpFile;
NTSTATUS status = STATUS_SUCCESS;
DWORD addrOut = INADDR_ANY;
@@ -705,7 +709,7 @@
case IFStatus: addrOut = ifInfo.if_info.ent.if_operstatus; break;
}
}
- closeTcpFile( &tcpFile );
+ closeTcpFile( tcpFile );
}
return addrOut;
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpap…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c (original)
+++ trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c Sun Dec 30 00:40:31 2007
@@ -604,13 +604,13 @@
unsigned long addr;
RegQueryValueExA(hKey, "WinsServer", NULL, NULL,
- primaryWINS.String, &size);
+ (PBYTE)primaryWINS.String, &size);
addr = inet_addr(primaryWINS.String);
if (addr != INADDR_NONE && addr != INADDR_ANY)
winsEnabled = TRUE;
size = sizeof(secondaryWINS.String);
RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL,
- secondaryWINS.String, &size);
+ (PBYTE)secondaryWINS.String, &size);
addr = inet_addr(secondaryWINS.String);
if (addr != INADDR_NONE && addr != INADDR_ANY)
winsEnabled = TRUE;
@@ -1390,7 +1390,7 @@
{
DWORD size = sizeof(pFixedInfo->ScopeId);
- RegQueryValueExA(hKey, "ScopeID", NULL, NULL, pFixedInfo->ScopeId,
&size);
+ RegQueryValueExA(hKey, "ScopeID", NULL, NULL,
(PBYTE)pFixedInfo->ScopeId, &size);
RegCloseKey(hKey);
}
Modified: trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/ipstats…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c (original)
+++ trunk/reactos/dll/win32/iphlpapi/ipstats_reactos.c Sun Dec 30 00:40:31 2007
@@ -404,6 +404,7 @@
if( !NT_SUCCESS(status) ) {
TRACE("failure: %08x\n", (int)status );
+ closeTcpFile( tcpFile );
return 0;
}
@@ -414,6 +415,7 @@
status = tdiGetMibForIpEntity( tcpFile, &entitySet[i], &isnmp );
if( !NT_SUCCESS(status) ) {
tdiFreeThingSet( entitySet );
+ closeTcpFile( tcpFile );
return status;
}
numRoutes += isnmp.ipsi_numroutes;
@@ -504,6 +506,8 @@
routesAdded += snmpInfo.ipsi_numroutes;
}
+ closeTcpFile( tcpFile );
+
TRACE("Return: %08x, %08x\n", status, out_route_table);
return out_route_table;
@@ -606,6 +610,8 @@
if( AdapterArpTable ) tdiFreeThingSet( AdapterArpTable );
}
}
+
+ closeTcpFile( tcpFile );
tdiFreeThingSet( entitySet );
IpArpTable->dwNumEntries = row;
Modified: trunk/reactos/dll/win32/iphlpapi/route_reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/route_r…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/route_reactos.c (original)
+++ trunk/reactos/dll/win32/iphlpapi/route_reactos.c Sun Dec 30 00:40:31 2007
@@ -53,7 +53,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
DWORD createIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
- HANDLE tcpFile = INVALID_HANDLE_VALUE;
+ HANDLE tcpFile;
NTSTATUS status = openTcpFile( &tcpFile );
TCP_REQUEST_SET_INFORMATION_EX_SAFELY_SIZED req =
TCP_REQUEST_SET_INFORMATION_INIT;
@@ -63,45 +63,45 @@
TRACE("Called.\n");
- if( NT_SUCCESS(status) )
+ if( NT_SUCCESS(status) ) {
status = getNthIpEntity( tcpFile, 0, &id );
- if( NT_SUCCESS(status) ) {
- req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
- req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
- req.Req.ID.toi_entity = id;
- req.Req.BufferSize = sizeof(*rte);
- rte =
- (IPRouteEntry *)&req.Req.Buffer[0];
+ if( NT_SUCCESS(status) ) {
+ req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
+ req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
+ req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
+ req.Req.ID.toi_entity = id;
+ req.Req.BufferSize = sizeof(*rte);
+ rte =
+ (IPRouteEntry *)&req.Req.Buffer[0];
- // dwForwardPolicy
- // dwForwardNextHopAS
- rte->ire_dest = pRoute->dwForwardDest;
- rte->ire_mask = pRoute->dwForwardMask;
- rte->ire_gw = pRoute->dwForwardNextHop;
- rte->ire_index = pRoute->dwForwardIfIndex;
- rte->ire_type = IP_FORWARD_ADD;
- rte->ire_proto = pRoute->dwForwardProto;
- rte->ire_age = pRoute->dwForwardAge;
- rte->ire_metric1 = pRoute->dwForwardMetric1;
- rte->ire_metric2 = pRoute->dwForwardMetric2;
- rte->ire_metric3 = pRoute->dwForwardMetric3;
- rte->ire_metric4 = pRoute->dwForwardMetric4;
- rte->ire_metric5 = pRoute->dwForwardMetric5;
+ // dwForwardPolicy
+ // dwForwardNextHopAS
+ rte->ire_dest = pRoute->dwForwardDest;
+ rte->ire_mask = pRoute->dwForwardMask;
+ rte->ire_gw = pRoute->dwForwardNextHop;
+ rte->ire_index = pRoute->dwForwardIfIndex;
+ rte->ire_type = IP_FORWARD_ADD;
+ rte->ire_proto = pRoute->dwForwardProto;
+ rte->ire_age = pRoute->dwForwardAge;
+ rte->ire_metric1 = pRoute->dwForwardMetric1;
+ rte->ire_metric2 = pRoute->dwForwardMetric2;
+ rte->ire_metric3 = pRoute->dwForwardMetric3;
+ rte->ire_metric4 = pRoute->dwForwardMetric4;
+ rte->ire_metric5 = pRoute->dwForwardMetric5;
- status = DeviceIoControl( tcpFile,
- IOCTL_TCP_SET_INFORMATION_EX,
- &req,
- sizeof(req),
- NULL,
- 0,
- &returnSize,
- NULL );
+ status = DeviceIoControl( tcpFile,
+ IOCTL_TCP_SET_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ NULL,
+ 0,
+ &returnSize,
+ NULL );
+ }
+
+ closeTcpFile( tcpFile );
}
-
- if( tcpFile != INVALID_HANDLE_VALUE )
- closeTcpFile( tcpFile );
TRACE("Returning: %08x (IOCTL was %08x)\n", status,
IOCTL_TCP_SET_INFORMATION_EX);
@@ -117,7 +117,7 @@
}
DWORD deleteIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
- HANDLE tcpFile = INVALID_HANDLE_VALUE;
+ HANDLE tcpFile;
NTSTATUS status = openTcpFile( &tcpFile );
TCP_REQUEST_SET_INFORMATION_EX_SAFELY_SIZED req =
TCP_REQUEST_SET_INFORMATION_INIT;
@@ -127,45 +127,45 @@
TRACE("Called.\n");
- if( NT_SUCCESS(status) )
+ if( NT_SUCCESS(status) ) {
status = getNthIpEntity( tcpFile, 0, &id );
- if( NT_SUCCESS(status) ) {
- req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
- req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
- req.Req.ID.toi_entity = id;
- req.Req.BufferSize = sizeof(*rte);
- rte =
- (IPRouteEntry *)&req.Req.Buffer[0];
+ if( NT_SUCCESS(status) ) {
+ req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
+ req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
+ req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
+ req.Req.ID.toi_entity = id;
+ req.Req.BufferSize = sizeof(*rte);
+ rte =
+ (IPRouteEntry *)&req.Req.Buffer[0];
- // dwForwardPolicy
- // dwForwardNextHopAS
- rte->ire_dest = pRoute->dwForwardDest;
- rte->ire_mask = INADDR_NONE;
- rte->ire_gw = pRoute->dwForwardNextHop;
- rte->ire_index = pRoute->dwForwardIfIndex;
- rte->ire_type = IP_FORWARD_DEL;
- rte->ire_proto = pRoute->dwForwardProto;
- rte->ire_age = pRoute->dwForwardAge;
- rte->ire_metric1 = pRoute->dwForwardMetric1;
- rte->ire_metric2 = INADDR_NONE;
- rte->ire_metric3 = INADDR_NONE;
- rte->ire_metric4 = INADDR_NONE;
- rte->ire_metric5 = INADDR_NONE;
+ // dwForwardPolicy
+ // dwForwardNextHopAS
+ rte->ire_dest = pRoute->dwForwardDest;
+ rte->ire_mask = INADDR_NONE;
+ rte->ire_gw = pRoute->dwForwardNextHop;
+ rte->ire_index = pRoute->dwForwardIfIndex;
+ rte->ire_type = IP_FORWARD_DEL;
+ rte->ire_proto = pRoute->dwForwardProto;
+ rte->ire_age = pRoute->dwForwardAge;
+ rte->ire_metric1 = pRoute->dwForwardMetric1;
+ rte->ire_metric2 = INADDR_NONE;
+ rte->ire_metric3 = INADDR_NONE;
+ rte->ire_metric4 = INADDR_NONE;
+ rte->ire_metric5 = INADDR_NONE;
- status = DeviceIoControl( tcpFile,
- IOCTL_TCP_SET_INFORMATION_EX,
- &req,
- sizeof(req),
- NULL,
- 0,
- &returnSize,
- NULL );
+ status = DeviceIoControl( tcpFile,
+ IOCTL_TCP_SET_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ NULL,
+ 0,
+ &returnSize,
+ NULL );
+ }
+
+ closeTcpFile( tcpFile );
}
-
- if( tcpFile != INVALID_HANDLE_VALUE )
- closeTcpFile( tcpFile );
TRACE("Returning: %08x (IOCTL was %08x)\n", status,
IOCTL_TCP_SET_INFORMATION_EX);