summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/pinfo.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/pinfo.cc')
-rw-r--r--winsup/cygwin/pinfo.cc42
1 files changed, 32 insertions, 10 deletions
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 180e935cf..e6c62e387 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -1323,29 +1323,51 @@ winpids::enum_processes (bool winpid)
if (winpid)
{
static DWORD szprocs;
- static SYSTEM_PROCESSES *procs;
+ static PSYSTEM_PROCESSES procs;
if (!szprocs)
- procs = (SYSTEM_PROCESSES *) malloc (sizeof (*procs) + (szprocs = 200 * sizeof (*procs)));
+ {
+ procs = (PSYSTEM_PROCESSES)
+ malloc (sizeof (*procs) + (szprocs = 200 * sizeof (*procs)));
+ if (!procs)
+ {
+ system_printf ("out of memory reading system process "
+ "information");
+ return 0;
+ }
+ }
- NTSTATUS res;
for (;;)
{
- res = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
+ status =
+ NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
procs, szprocs, NULL);
- if (res == 0)
+ if (NT_SUCCESS (status))
break;
- if (res == STATUS_INFO_LENGTH_MISMATCH)
- procs = (SYSTEM_PROCESSES *) realloc (procs, szprocs += 200 * sizeof (*procs));
+ if (status == STATUS_INFO_LENGTH_MISMATCH)
+ {
+ PSYSTEM_PROCESSES new_p;
+
+ new_p = (PSYSTEM_PROCESSES)
+ realloc (procs, szprocs += 200 * sizeof (*procs));
+ if (!new_p)
+ {
+ system_printf ("out of memory reading system process "
+ "information");
+ return 0;
+ }
+ procs = new_p;
+ }
else
{
- system_printf ("error %p reading system process information", res);
+ system_printf ("error %p reading system process information",
+ status);
return 0;
}
}
- SYSTEM_PROCESSES *px = procs;
+ PSYSTEM_PROCESSES px = procs;
for (;;)
{
if (px->ProcessId)
@@ -1362,7 +1384,7 @@ winpids::enum_processes (bool winpid)
}
if (!px->NextEntryDelta)
break;
- px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta);
+ px = (PSYSTEM_PROCESSES) ((char *) px + px->NextEntryDelta);
}
}