From 85e01470a45f33992aee04ad6493df3662348c97 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 12 Aug 2011 08:12:47 +0000 Subject: [PATCH] [IPHLPAPI] - Fix a massive memory leak of our entire TDI entity ID database after each call to getInterfaceInfoSet - Fix another massive leak of our entire TDI interface table after each call to getInterfaceInfoByIndex and getInterfaceInfoByName - Fix some uninitialized variable warnings - Explorer no longer leaks horrendous amounts of memory (about 1 MB per minute even without network activity) when the network status icon is in the system tray svn path=/trunk/; revision=53190 --- reactos/dll/win32/iphlpapi/ifenum_reactos.c | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/reactos/dll/win32/iphlpapi/ifenum_reactos.c b/reactos/dll/win32/iphlpapi/ifenum_reactos.c index e637a4a78a3..fd6c787304d 100644 --- a/reactos/dll/win32/iphlpapi/ifenum_reactos.c +++ b/reactos/dll/win32/iphlpapi/ifenum_reactos.c @@ -202,6 +202,8 @@ static NTSTATUS getInterfaceInfoSet( HANDLE tcpFile, } } + tdiFreeThingSet(entIDSet); + if (NT_SUCCESS(status)) { *infoSet = infoSetInt; *numInterfaces = curInterf; @@ -285,12 +287,12 @@ DWORD getNthInterfaceEntity( HANDLE tcpFile, DWORD index, TDIEntityID *ent ) { TRACE("Index %d is entity #%d - %04x:%08x\n", index, i, entitySet[i].tei_entity, entitySet[i].tei_instance ); + tdiFreeThingSet( entitySet ); + if( numInterfaces == index && i < numEntities ) { memcpy( ent, &entitySet[i], sizeof(*ent) ); - tdiFreeThingSet( entitySet ); return STATUS_SUCCESS; } else { - tdiFreeThingSet( entitySet ); return STATUS_UNSUCCESSFUL; } } @@ -302,6 +304,7 @@ NTSTATUS getInterfaceInfoByIndex( HANDLE tcpFile, DWORD index, IFInfo *info ) { int i; if( NT_SUCCESS(status) ) + { for( i = 0; i < numInterfaces; i++ ) { if( ifInfo[i].if_info.ent.if_index == index ) { memcpy( info, &ifInfo[i], sizeof(*info) ); @@ -309,10 +312,12 @@ NTSTATUS getInterfaceInfoByIndex( HANDLE tcpFile, DWORD index, IFInfo *info ) { } } - if( NT_SUCCESS(status) ) + HeapFree(GetProcessHeap(), 0, ifInfo); + return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; - else - return status; + } + + return status; } NTSTATUS getInterfaceInfoByName( HANDLE tcpFile, char *name, IFInfo *info ) { @@ -322,6 +327,7 @@ NTSTATUS getInterfaceInfoByName( HANDLE tcpFile, char *name, IFInfo *info ) { NTSTATUS status = getInterfaceInfoSet( tcpFile, &ifInfo, &numInterfaces ); if( NT_SUCCESS(status) ) + { for( i = 0; i < numInterfaces; i++ ) { if( !strcmp((PCHAR)ifInfo[i].if_info.ent.if_descr, name) ) { memcpy( info, &ifInfo[i], sizeof(*info) ); @@ -329,10 +335,12 @@ NTSTATUS getInterfaceInfoByName( HANDLE tcpFile, char *name, IFInfo *info ) { } } - if( NT_SUCCESS(status) ) + HeapFree(GetProcessHeap(), 0,ifInfo); + return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; - else - return status; + } + + return status; } /* Note that the result of this operation must be freed later */