From 85672737e62842cc5e955dd711154cfd3c2293aa Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 5 Sep 2008 19:51:18 +0000 Subject: [PATCH] - Handle AllocatedResources and AllocatedResourcesTranslated separately - Fix a memory leak - Fix a handle leak svn path=/branches/aicom-network-fixes/; revision=35964 --- drivers/network/ndis/ndis/miniport.c | 24 +++++++++++++++--------- drivers/network/ndis/ndis/protocol.c | 6 ++++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/network/ndis/ndis/miniport.c b/drivers/network/ndis/ndis/miniport.c index 8537cd7a898..d499f285ff7 100644 --- a/drivers/network/ndis/ndis/miniport.c +++ b/drivers/network/ndis/ndis/miniport.c @@ -1293,8 +1293,7 @@ NdisIPnPStartDevice( * NdisMQueryAdapterResources. */ - if (Stack->Parameters.StartDevice.AllocatedResources != NULL && - Stack->Parameters.StartDevice.AllocatedResourcesTranslated != NULL) + if (Stack->Parameters.StartDevice.AllocatedResources != NULL) { ResourceCount = Stack->Parameters.StartDevice.AllocatedResources->List[0]. PartialResourceList.Count; @@ -1310,24 +1309,31 @@ NdisIPnPStartDevice( return STATUS_INSUFFICIENT_RESOURCES; } + RtlCopyMemory(Adapter->NdisMiniportBlock.AllocatedResources, + Stack->Parameters.StartDevice.AllocatedResources, + ResourceListSize); + } + + if (Stack->Parameters.StartDevice.AllocatedResourcesTranslated != NULL) + { + ResourceCount = Stack->Parameters.StartDevice.AllocatedResources->List[0]. + PartialResourceList.Count; + ResourceListSize = + FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList. + PartialDescriptors[ResourceCount]); + Adapter->NdisMiniportBlock.AllocatedResourcesTranslated = ExAllocatePool(PagedPool, ResourceListSize); if (Adapter->NdisMiniportBlock.AllocatedResourcesTranslated == NULL) { - ExFreePool(Adapter->NdisMiniportBlock.AllocatedResources); - Adapter->NdisMiniportBlock.AllocatedResources = NULL; ExInterlockedRemoveEntryList( &Adapter->ListEntry, &AdapterListLock ); return STATUS_INSUFFICIENT_RESOURCES; } - RtlCopyMemory(Adapter->NdisMiniportBlock.AllocatedResources, - Stack->Parameters.StartDevice.AllocatedResources, - ResourceListSize); - RtlCopyMemory(Adapter->NdisMiniportBlock.AllocatedResourcesTranslated, Stack->Parameters.StartDevice.AllocatedResourcesTranslated, ResourceListSize); - } + } /* * Store the Bus Type, Bus Number and Slot information. It's used by diff --git a/drivers/network/ndis/ndis/protocol.c b/drivers/network/ndis/ndis/protocol.c index e2ac8bb649f..b9fa3729792 100644 --- a/drivers/network/ndis/ndis/protocol.c +++ b/drivers/network/ndis/ndis/protocol.c @@ -805,10 +805,11 @@ NdisRegisterProtocol( NtStatus = ZwQueryValueKey(DriverKeyHandle, &ValueName, KeyValuePartialInformation, KeyInformation, sizeof(KEY_VALUE_PARTIAL_INFORMATION) + ResultLength, &ResultLength); + ZwClose(DriverKeyHandle); + if(!NT_SUCCESS(NtStatus)) { NDIS_DbgPrint(MIN_TRACE, ("Unable to query the Bind value\n")); - ZwClose(DriverKeyHandle); ExFreePool(KeyInformation); ExFreePool(Protocol); *Status = NDIS_STATUS_FAILURE; @@ -893,7 +894,8 @@ NdisRegisterProtocol( */ } - *Status = NDIS_STATUS_SUCCESS; + ExFreePool(KeyInformation); + *Status = NDIS_STATUS_SUCCESS; }