[ros-diffs] [cgutman] 43032: - Fix memory leaks when reading strings and binary values from the registry - Fix list manipulation

cgutman at svn.reactos.org cgutman at svn.reactos.org
Sat Sep 12 04:26:33 CEST 2009


Author: cgutman
Date: Sat Sep 12 04:26:33 2009
New Revision: 43032

URL: http://svn.reactos.org/svn/reactos?rev=43032&view=rev
Log:
 - Fix memory leaks when reading strings and binary values from the registry
 - Fix list manipulation

Modified:
    trunk/reactos/drivers/network/ndis/include/miniport.h
    trunk/reactos/drivers/network/ndis/ndis/config.c

Modified: trunk/reactos/drivers/network/ndis/include/miniport.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/include/miniport.h?rev=43032&r1=43031&r2=43032&view=diff
==============================================================================
--- trunk/reactos/drivers/network/ndis/include/miniport.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/ndis/include/miniport.h [iso-8859-1] Sat Sep 12 04:26:33 2009
@@ -41,7 +41,8 @@
 } NDIS_M_DEVICE_BLOCK, *PNDIS_M_DEVICE_BLOCK;
 
 /* resources allocated on behalf on the miniport */
-#define MINIPORT_RESOURCE_TYPE_MEMORY 0
+#define MINIPORT_RESOURCE_TYPE_REGISTRY_DATA 0
+#define MINIPORT_RESOURCE_TYPE_MEMORY        1
 typedef struct _MINIPORT_RESOURCE {
     LIST_ENTRY     ListEntry;
     ULONG          ResourceType;

Modified: trunk/reactos/drivers/network/ndis/ndis/config.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/ndis/ndis/config.c?rev=43032&r1=43031&r2=43032&view=diff
==============================================================================
--- trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] Sat Sep 12 04:26:33 2009
@@ -139,14 +139,43 @@
 {
     PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext = (PMINIPORT_CONFIGURATION_CONTEXT)ConfigurationHandle;
     PMINIPORT_RESOURCE Resource;
-
-    while(!IsListEmpty(&ConfigurationContext->ResourceListHead))
-    {
-        Resource = (PMINIPORT_RESOURCE)ExInterlockedRemoveHeadList(&ConfigurationContext->ResourceListHead, &ConfigurationContext->ResourceLock);
-        if(Resource->ResourceType == MINIPORT_RESOURCE_TYPE_MEMORY)
+    PNDIS_CONFIGURATION_PARAMETER ParameterValue;
+    PLIST_ENTRY CurrentEntry;
+
+    while((CurrentEntry = ExInterlockedRemoveHeadList(&ConfigurationContext->ResourceListHead,
+                                                      &ConfigurationContext->ResourceLock)) != NULL)
+    {
+        Resource = CONTAINING_RECORD(CurrentEntry, MINIPORT_RESOURCE, ListEntry);
+        switch(Resource->ResourceType)
         {
+          case MINIPORT_RESOURCE_TYPE_REGISTRY_DATA:
+            ParameterValue = Resource->Resource;
+
+            switch (ParameterValue->ParameterType)
+            {
+               case NdisParameterBinary:
+                 ExFreePool(ParameterValue->ParameterData.BinaryData.Buffer);
+                 break;
+
+               case NdisParameterString:
+               case NdisParameterMultiString:
+                 ExFreePool(ParameterValue->ParameterData.StringData.Buffer);
+                 break;
+
+               default:
+                 break;
+            }
+
+          /* Fall through to free NDIS_CONFIGURATION_PARAMETER struct */
+
+          case MINIPORT_RESOURCE_TYPE_MEMORY:
             NDIS_DbgPrint(MAX_TRACE,("freeing 0x%x\n", Resource->Resource));
             ExFreePool(Resource->Resource);
+            break;
+
+          default:
+            NDIS_DbgPrint(MIN_TRACE,("Unknown resource type: %d\n", Resource->ResourceType));
+            break;
         }
 
         ExFreePool(Resource);
@@ -359,7 +388,7 @@
             return;
         }
 
-        MiniportResource->ResourceType = 0;
+        MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
         MiniportResource->Resource = *ParameterValue;
 
         NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n",
@@ -398,7 +427,7 @@
             return;
         }
 
-        MiniportResource->ResourceType = 0;
+        MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
         MiniportResource->Resource = *ParameterValue;
         NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
         ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
@@ -434,7 +463,7 @@
             return;
         }
 
-        MiniportResource->ResourceType = 0;
+        MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
         MiniportResource->Resource = *ParameterValue;
         NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
         ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
@@ -578,7 +607,7 @@
          }
     }
 
-    MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_MEMORY;
+    MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_REGISTRY_DATA;
     MiniportResource->Resource = *ParameterValue;
 
     ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
@@ -731,7 +760,7 @@
         return;
     }
 
-    MiniportResource->ResourceType = 0;
+    MiniportResource->ResourceType = MINIPORT_RESOURCE_TYPE_MEMORY;
     MiniportResource->Resource = IntArray;
     NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
     ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);




More information about the Ros-diffs mailing list