update for HEAD-2003021201
[reactos.git] / ntoskrnl / mm / region.c
index 1070666..4f87a9c 100644 (file)
@@ -183,12 +183,11 @@ MmAlterRegion(PMADDRESS_SPACE AddressSpace, PVOID BaseAddress,
    * and call the helper function to actually do the changes.
    */
   CurrentEntry = NewRegion->RegionListEntry.Flink;
+  CurrentRegion = CONTAINING_RECORD(CurrentEntry, MM_REGION, 
+                                   RegionListEntry);
   CurrentBaseAddress = StartAddress + NewRegion->Length;
   while (RemainingLength > 0 && CurrentRegion->Length <= RemainingLength)
     {
-      CurrentRegion = CONTAINING_RECORD(CurrentEntry, MM_REGION, 
-                                       RegionListEntry);
-      CurrentEntry = CurrentEntry->Flink;      
       if (CurrentRegion->Type != NewType &&
          CurrentRegion->Protect != NewProtect)
        {
@@ -199,8 +198,11 @@ MmAlterRegion(PMADDRESS_SPACE AddressSpace, PVOID BaseAddress,
       CurrentBaseAddress += CurrentRegion->Length;
       NewRegion->Length += CurrentRegion->Length;
       RemainingLength -= CurrentRegion->Length;
+      CurrentEntry = CurrentEntry->Flink;      
       RemoveEntryList(&CurrentRegion->RegionListEntry);
       ExFreePool(CurrentRegion);
+      CurrentRegion = CONTAINING_RECORD(CurrentEntry, MM_REGION, 
+                                       RegionListEntry);
     }
 
   /*