From 49ef6618c2e101953032b2c660bf7b246d07ce2d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 28 Mar 2018 13:23:53 +0100 Subject: ps: clear status for each process The original procps_scan function takes care to clear the status information before handling each process. Do the same for the WIN32 version. This requires moving the snapshot handle to the part of the structure that isn't cleared on each iteration. --- include/libbb.h | 7 ++++--- win32/process.c | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 2c0e02971..244d85e84 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1840,7 +1840,11 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, void (*cb)(struct smaprec *, void *), void *data); typedef struct procps_status_t { +#if !ENABLE_PLATFORM_MINGW32 DIR *dir; +#else + HANDLE snapshot; +#endif IF_FEATURE_SHOW_THREADS(DIR *task_dir;) uint8_t shift_pages_to_bytes; uint8_t shift_pages_to_kb; @@ -1879,9 +1883,6 @@ typedef struct procps_status_t { #if ENABLE_FEATURE_TOP_SMP_PROCESS int last_seen_on_cpu; #endif -#if ENABLE_PLATFORM_MINGW32 - HANDLE snapshot; -#endif } procps_status_t; /* flag bits for procps_scan(xx, flags) calls */ enum { diff --git a/win32/process.c b/win32/process.c index 84613cfdb..e835be63a 100644 --- a/win32/process.c +++ b/win32/process.c @@ -433,6 +433,8 @@ UNUSED_PARAM } } + memset(&sp->vsz, 0, sizeof(*sp) - offsetof(procps_status_t, vsz)); + #if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG if (flags & (PSSCAN_STIME|PSSCAN_UTIME|PSSCAN_START_TIME)) { HANDLE proc; -- cgit v1.2.3-55-g6feb