[NTOSKRNL]
authorCameron Gutman <aicommander@gmail.com>
Tue, 29 Nov 2011 08:13:56 +0000 (08:13 +0000)
committerCameron Gutman <aicommander@gmail.com>
Tue, 29 Nov 2011 08:13:56 +0000 (08:13 +0000)
- Fix a potential infinite loop in MmTrimUserMemory if we can't page out enough pages to meet the balancer's target

svn path=/trunk/; revision=54534

reactos/ntoskrnl/mm/balance.c

index c6dd93b..8c6e4fe 100644 (file)
@@ -164,14 +164,12 @@ MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
     PFN_NUMBER CurrentPage;
     PFN_NUMBER NextPage;
     NTSTATUS Status;
     PFN_NUMBER CurrentPage;
     PFN_NUMBER NextPage;
     NTSTATUS Status;
-    
+
     (*NrFreedPages) = 0;
     (*NrFreedPages) = 0;
-    
+
     CurrentPage = MmGetLRUFirstUserPage();
     while (CurrentPage != 0 && Target > 0)
     {
     CurrentPage = MmGetLRUFirstUserPage();
     while (CurrentPage != 0 && Target > 0)
     {
-        NextPage = MmGetLRUNextUserPage(CurrentPage);
-        
         Status = MmPageOutPhysicalAddress(CurrentPage);
         if (NT_SUCCESS(Status))
         {
         Status = MmPageOutPhysicalAddress(CurrentPage);
         if (NT_SUCCESS(Status))
         {
@@ -179,10 +177,17 @@ MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
             Target--;
             (*NrFreedPages)++;
         }
             Target--;
             (*NrFreedPages)++;
         }
-        
+
+        NextPage = MmGetLRUNextUserPage(CurrentPage);
+        if (NextPage <= CurrentPage)
+        {
+            /* We wrapped around, so we're done */
+            break;
+        }
         CurrentPage = NextPage;
     }
         CurrentPage = NextPage;
     }
-    return(STATUS_SUCCESS);
+
+    return STATUS_SUCCESS;
 }
 
 VOID
 }
 
 VOID