From c905ca8a310937f165e3b9b7cefc1ed6f7172445 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 24 Aug 2005 02:20:41 +0000 Subject: [PATCH] Get rid of one memory leak and two more ROS-only fields in LOGICAL_ADAPTER structure. svn path=/trunk/; revision=17498 --- reactos/drivers/net/ndis/include/miniport.h | 3 +- reactos/drivers/net/ndis/ndis/miniport.c | 70 +++++---------------- 2 files changed, 17 insertions(+), 56 deletions(-) diff --git a/reactos/drivers/net/ndis/include/miniport.h b/reactos/drivers/net/ndis/include/miniport.h index c8baf36aebf..a769365454c 100644 --- a/reactos/drivers/net/ndis/include/miniport.h +++ b/reactos/drivers/net/ndis/include/miniport.h @@ -80,8 +80,6 @@ typedef struct _LOGICAL_ADAPTER LIST_ENTRY ListEntry; /* Entry on global list */ LIST_ENTRY MiniportListEntry; /* Entry on miniport driver list */ LIST_ENTRY ProtocolListHead; /* List of bound protocols */ - PVOID QueryBuffer; /* Buffer to use for queries */ - ULONG QueryBufferLength; /* Length of QueryBuffer */ ULONG MediumHeaderSize; /* Size of medium header */ HARDWARE_ADDRESS Address; /* Hardware address of adapter */ ULONG AddressLength; /* Length of hardware address */ @@ -128,6 +126,7 @@ MiniQueryInformation( PLOGICAL_ADAPTER Adapter, NDIS_OID Oid, ULONG Size, + PVOID Buffer, PULONG BytesWritten); NDIS_STATUS diff --git a/reactos/drivers/net/ndis/ndis/miniport.c b/reactos/drivers/net/ndis/ndis/miniport.c index 8c7039d91e2..adefcb3ed70 100644 --- a/reactos/drivers/net/ndis/ndis/miniport.c +++ b/reactos/drivers/net/ndis/ndis/miniport.c @@ -548,13 +548,15 @@ MiniQueryInformation( PLOGICAL_ADAPTER Adapter, NDIS_OID Oid, ULONG Size, + PVOID Buffer, PULONG BytesWritten) /* * FUNCTION: Queries a logical adapter for properties * ARGUMENTS: * Adapter = Pointer to the logical adapter object to query * Oid = Specifies the Object ID to query for - * Size = If non-zero overrides the length in the adapter object + * Size = Size of the passed buffer + * Buffer = Buffer for the output * BytesWritten = Address of buffer to place number of bytes written * NOTES: * If the specified buffer is too small, a new buffer is allocated, @@ -570,33 +572,17 @@ MiniQueryInformation( NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n")); - if (Adapter->QueryBufferLength == 0) - { - /* XXX is 32 the right number? */ - Adapter->QueryBuffer = ExAllocatePool(NonPagedPool, (Size == 0)? 32 : Size); - - if (!Adapter->QueryBuffer) - { - NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n")); - return NDIS_STATUS_RESOURCES; - } - - /* ditto */ - Adapter->QueryBufferLength = (Size == 0)? 32 : Size; - } - - /* this is the third time i've seen this conditional */ - BytesNeeded = (Size == 0)? Adapter->QueryBufferLength : Size; - /* call the miniport's queryinfo handler */ NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.QueryInformationHandler)( Adapter->NdisMiniportBlock.MiniportAdapterContext, Oid, - Adapter->QueryBuffer, - BytesNeeded, + Buffer, + Size, BytesWritten, &BytesNeeded); + /* FIXME: Wait in pending case! */ + /* XXX is status_pending part of success macro? */ if ((NT_SUCCESS(NdisStatus)) || (NdisStatus == NDIS_STATUS_PENDING)) { @@ -604,28 +590,6 @@ MiniQueryInformation( return NdisStatus; } - if (NdisStatus == NDIS_STATUS_INVALID_LENGTH) - { - ExFreePool(Adapter->QueryBuffer); - - Adapter->QueryBufferLength += BytesNeeded; - Adapter->QueryBuffer = ExAllocatePool(NonPagedPool, Adapter->QueryBufferLength); - - if (!Adapter->QueryBuffer) - { - NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n")); - return NDIS_STATUS_RESOURCES; - } - - NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.QueryInformationHandler)( - Adapter->NdisMiniportBlock.MiniportAdapterContext, - Oid, - Adapter->QueryBuffer, - Adapter->QueryBufferLength, - BytesWritten, - &BytesNeeded); - } - return NdisStatus; } @@ -1167,7 +1131,9 @@ DoQueries( NDIS_DbgPrint(MAX_TRACE, ("Called.\n")); /* Get MAC options for adapter */ - NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MAC_OPTIONS, 0, &BytesWritten); + NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MAC_OPTIONS, sizeof(UINT), + &Adapter->NdisMiniportBlock.MacOptions, + &BytesWritten); if (NdisStatus != NDIS_STATUS_SUCCESS) { @@ -1175,12 +1141,11 @@ DoQueries( return NdisStatus; } - RtlCopyMemory(&Adapter->NdisMiniportBlock.MacOptions, Adapter->QueryBuffer, sizeof(UINT)); - NDIS_DbgPrint(DEBUG_MINIPORT, ("MacOptions (0x%X).\n", Adapter->NdisMiniportBlock.MacOptions)); /* Get current hardware address of adapter */ - NdisStatus = MiniQueryInformation(Adapter, AddressOID, 0, &BytesWritten); + NdisStatus = MiniQueryInformation(Adapter, AddressOID, Adapter->AddressLength, + &Adapter->Address, &BytesWritten); if (NdisStatus != NDIS_STATUS_SUCCESS) { @@ -1188,7 +1153,6 @@ DoQueries( return NdisStatus; } - RtlCopyMemory(&Adapter->Address, Adapter->QueryBuffer, Adapter->AddressLength); #ifdef DBG { /* 802.3 only */ @@ -1200,7 +1164,8 @@ DoQueries( #endif /* DBG */ /* Get maximum lookahead buffer size of adapter */ - NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MAXIMUM_LOOKAHEAD, 0, &BytesWritten); + NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MAXIMUM_LOOKAHEAD, sizeof(ULONG), + &Adapter->NdisMiniportBlock.MaximumLookahead, &BytesWritten); if (NdisStatus != NDIS_STATUS_SUCCESS) { @@ -1208,12 +1173,11 @@ DoQueries( return NdisStatus; } - Adapter->NdisMiniportBlock.MaximumLookahead = *((PULONG)Adapter->QueryBuffer); - NDIS_DbgPrint(DEBUG_MINIPORT, ("MaxLookaheadLength (0x%X).\n", Adapter->NdisMiniportBlock.MaximumLookahead)); /* Get current lookahead buffer size of adapter */ - NdisStatus = MiniQueryInformation(Adapter, OID_GEN_CURRENT_LOOKAHEAD, 0, &BytesWritten); + NdisStatus = MiniQueryInformation(Adapter, OID_GEN_CURRENT_LOOKAHEAD, sizeof(ULONG), + &Adapter->NdisMiniportBlock.CurrentLookahead, &BytesWritten); if (NdisStatus != NDIS_STATUS_SUCCESS) { @@ -1221,8 +1185,6 @@ DoQueries( return NdisStatus; } - Adapter->NdisMiniportBlock.CurrentLookahead = *((PULONG)Adapter->QueryBuffer); - NDIS_DbgPrint(DEBUG_MINIPORT, ("CurLookaheadLength (0x%X).\n", Adapter->NdisMiniportBlock.CurrentLookahead)); if (Adapter->NdisMiniportBlock.MaximumLookahead != 0)