diff --git a/SystemInformer/mainwnd.c b/SystemInformer/mainwnd.c index 2cbb331f998e..d8eaf9de9c7a 100644 --- a/SystemInformer/mainwnd.c +++ b/SystemInformer/mainwnd.c @@ -1749,11 +1749,13 @@ VOID PhMwpOnCommand( PPH_PROCESS_ITEM *processes; ULONG numberOfProcesses; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - PhReferenceObjects(processes, numberOfProcesses); - PhUiReduceWorkingSetProcesses(WindowHandle, processes, numberOfProcesses); - PhDereferenceObjects(processes, numberOfProcesses); - PhFree(processes); + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) + { + PhReferenceObjects(processes, numberOfProcesses); + PhUiReduceWorkingSetProcesses(WindowHandle, processes, numberOfProcesses); + PhDereferenceObjects(processes, numberOfProcesses); + PhFree(processes); + } } break; case ID_MISCELLANEOUS_RUNAS: @@ -1805,11 +1807,13 @@ VOID PhMwpOnCommand( PPH_PROCESS_ITEM* processes; ULONG numberOfProcesses; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - PhReferenceObjects(processes, numberOfProcesses); - PhUiFlushHeapProcesses(WindowHandle, processes, numberOfProcesses); - PhDereferenceObjects(processes, numberOfProcesses); - PhFree(processes); + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) + { + PhReferenceObjects(processes, numberOfProcesses); + PhUiFlushHeapProcesses(WindowHandle, processes, numberOfProcesses); + PhDereferenceObjects(processes, numberOfProcesses); + PhFree(processes); + } } break; case ID_PRIORITY_REALTIME: @@ -1822,11 +1826,13 @@ VOID PhMwpOnCommand( PPH_PROCESS_ITEM *processes; ULONG numberOfProcesses; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - PhReferenceObjects(processes, numberOfProcesses); - PhMwpExecuteProcessPriorityCommand(WindowHandle, Id, processes, numberOfProcesses); - PhDereferenceObjects(processes, numberOfProcesses); - PhFree(processes); + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) + { + PhReferenceObjects(processes, numberOfProcesses); + PhMwpExecuteProcessPriorityCommand(WindowHandle, Id, processes, numberOfProcesses); + PhDereferenceObjects(processes, numberOfProcesses); + PhFree(processes); + } } break; case ID_IOPRIORITY_VERYLOW: @@ -1837,11 +1843,13 @@ VOID PhMwpOnCommand( PPH_PROCESS_ITEM *processes; ULONG numberOfProcesses; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - PhReferenceObjects(processes, numberOfProcesses); - PhMwpExecuteProcessIoPriorityCommand(WindowHandle, Id, processes, numberOfProcesses); - PhDereferenceObjects(processes, numberOfProcesses); - PhFree(processes); + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) + { + PhReferenceObjects(processes, numberOfProcesses); + PhMwpExecuteProcessIoPriorityCommand(WindowHandle, Id, processes, numberOfProcesses); + PhDereferenceObjects(processes, numberOfProcesses); + PhFree(processes); + } } break; case ID_MISCELLANEOUS_ECOMODE: diff --git a/SystemInformer/mwpgproc.c b/SystemInformer/mwpgproc.c index ffc194e28c23..84e724a506e6 100644 --- a/SystemInformer/mwpgproc.c +++ b/SystemInformer/mwpgproc.c @@ -976,9 +976,7 @@ VOID PhShowProcessContextMenu( PPH_PROCESS_ITEM *processes; ULONG numberOfProcesses; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - - if (numberOfProcesses != 0) + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) { PPH_EMENU menu; PPH_EMENU_ITEM item; @@ -1025,9 +1023,9 @@ VOID PhShowProcessContextMenu( } PhDestroyEMenu(menu); - } - PhFree(processes); + PhFree(processes); + } } VOID NTAPI PhMwpProcessAddedHandler( diff --git a/SystemInformer/proctree.c b/SystemInformer/proctree.c index b5bd3531f3bb..d10616456409 100644 --- a/SystemInformer/proctree.c +++ b/SystemInformer/proctree.c @@ -5286,6 +5286,9 @@ BOOLEAN PhGetSelectedProcessItems( } else { + *NumberOfProcesses = 0; + *Processes = NULL; + PhDeleteArray(&array); return FALSE; } } diff --git a/plugins/UserNotes/main.c b/plugins/UserNotes/main.c index 733cb7b81534..14b21056dc7c 100644 --- a/plugins/UserNotes/main.c +++ b/plugins/UserNotes/main.c @@ -1693,27 +1693,29 @@ VOID NTAPI MenuHookCallback( ULONG numberOfProcesses; ULONG i; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - LockDb(); - - for (i = 0; i < numberOfProcesses; i++) + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) { - PDB_OBJECT object; + LockDb(); - if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PRIORITY_CLASS)) + for (i = 0; i < numberOfProcesses; i++) { - ULONG newPriorityClass = GetPriorityClassFromId(id); + PDB_OBJECT object; - if (object->PriorityClass != newPriorityClass) + if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PRIORITY_CLASS)) { - object->PriorityClass = newPriorityClass; - changed = TRUE; + ULONG newPriorityClass = GetPriorityClassFromId(id); + + if (object->PriorityClass != newPriorityClass) + { + object->PriorityClass = newPriorityClass; + changed = TRUE; + } } } - } - UnlockDb(); - PhFree(processes); + UnlockDb(); + PhFree(processes); + } if (changed) SaveDb(); @@ -1729,27 +1731,29 @@ VOID NTAPI MenuHookCallback( ULONG numberOfProcesses; ULONG i; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - LockDb(); - - for (i = 0; i < numberOfProcesses; i++) + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) { - PDB_OBJECT object; + LockDb(); - if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_IO_PRIORITY)) + for (i = 0; i < numberOfProcesses; i++) { - ULONG newIoPriorityPlusOne = GetIoPriorityFromId(id) + 1; + PDB_OBJECT object; - if (object->IoPriorityPlusOne != newIoPriorityPlusOne) + if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_IO_PRIORITY)) { - object->IoPriorityPlusOne = newIoPriorityPlusOne; - changed = TRUE; + ULONG newIoPriorityPlusOne = GetIoPriorityFromId(id) + 1; + + if (object->IoPriorityPlusOne != newIoPriorityPlusOne) + { + object->IoPriorityPlusOne = newIoPriorityPlusOne; + changed = TRUE; + } } } - } - UnlockDb(); - PhFree(processes); + UnlockDb(); + PhFree(processes); + } if (changed) SaveDb(); @@ -1766,27 +1770,29 @@ VOID NTAPI MenuHookCallback( ULONG numberOfProcesses; ULONG i; - PhGetSelectedProcessItems(&processes, &numberOfProcesses); - LockDb(); - - for (i = 0; i < numberOfProcesses; i++) + if (PhGetSelectedProcessItems(&processes, &numberOfProcesses)) { - PDB_OBJECT object; + LockDb(); - if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PAGEPRIORITY)) + for (i = 0; i < numberOfProcesses; i++) { - ULONG newPagePriorityPlusOne = GetPagePriorityFromId(id) + 1; + PDB_OBJECT object; - if (object->PagePriorityPlusOne != newPagePriorityPlusOne) + if (object = FindDbObjectForProcess(processes[i], INTENT_PROCESS_PAGEPRIORITY)) { - object->PagePriorityPlusOne = newPagePriorityPlusOne; - changed = TRUE; + ULONG newPagePriorityPlusOne = GetPagePriorityFromId(id) + 1; + + if (object->PagePriorityPlusOne != newPagePriorityPlusOne) + { + object->PagePriorityPlusOne = newPagePriorityPlusOne; + changed = TRUE; + } } } - } - UnlockDb(); - PhFree(processes); + UnlockDb(); + PhFree(processes); + } if (changed) SaveDb(); @@ -1997,7 +2003,7 @@ VOID TreeNewMessageCallback( } break; } - + } else if (message->TreeNewHandle == ServiceTreeNewHandle) { @@ -2345,7 +2351,7 @@ VOID ProcessTreeNewInitializingCallback( affinity.Text = L"Affinity"; affinity.Width = 120; affinity.Alignment = PH_ALIGN_LEFT; - + PhPluginAddTreeNewColumn(PluginInstance, info->CmData, &column, COMMENT_COLUMN_ID, NULL, ProcessCommentSortFunction); PhPluginAddTreeNewColumn(PluginInstance, info->CmData, &affinity, AFFINITY_COLUMN_ID, NULL, ProcessAffinitySortFunction); }