[WIN32K:NTUSER] Handle realloc failure in IntRemoveMenuItem. CORE-14222
authorThomas Faber <thomas.faber@reactos.org>
Thu, 1 Feb 2018 10:06:50 +0000 (11:06 +0100)
committerThomas Faber <thomas.faber@reactos.org>
Sun, 18 Feb 2018 10:27:29 +0000 (11:27 +0100)
win32ss/user/ntuser/menu.c

index 8432f3a..5ecffbb 100644 (file)
@@ -598,6 +598,7 @@ BOOL FASTCALL
 IntRemoveMenuItem( PMENU pMenu, UINT nPos, UINT wFlags, BOOL bRecurse )
 {
     PITEM item;
+    PITEM newItems;
 
     TRACE("(menu=%p pos=%04x flags=%04x)\n",pMenu, nPos, wFlags);
     if (!(item = MENU_FindItem( &pMenu, &nPos, wFlags ))) return FALSE;
@@ -617,13 +618,17 @@ IntRemoveMenuItem( PMENU pMenu, UINT nPos, UINT wFlags, BOOL bRecurse )
     }
     else
     {
-       while(nPos < pMenu->cItems)
-       {
-           *item = *(item+1);
-           item++;
-           nPos++;
-       }
-       pMenu->rgItems = DesktopHeapReAlloc(pMenu->head.rpdesk, pMenu->rgItems, pMenu->cItems * sizeof(ITEM));
+        while (nPos < pMenu->cItems)
+        {
+            *item = *(item+1);
+            item++;
+            nPos++;
+        }
+        newItems = DesktopHeapReAlloc(pMenu->head.rpdesk, pMenu->rgItems, pMenu->cItems * sizeof(ITEM));
+        if (newItems)
+        {
+            pMenu->rgItems = newItems;
+        }
     }
     return TRUE;
 }