diff --git a/src/os/win32/peb.c b/src/os/win32/peb.c index 153effe9..ed0147d1 100644 --- a/src/os/win32/peb.c +++ b/src/os/win32/peb.c @@ -171,15 +171,16 @@ int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc, } size = rtl_bufsize(buf, rtl.CommandLine); + if (size <= 0) { + return ERROR_DATATYPE_MISMATCH; /* fallback to wmi */ + } memset(buf, '\0', sizeof(buf)); - - if ((size > 0) && - ReadProcessMemory(proc, rtl.CommandLine.Buffer, buf, size, NULL)) - { + + if (ReadProcessMemory(proc, rtl.CommandLine.Buffer, buf, size, NULL)) { return sigar_parse_proc_args(sigar, buf, procargs); } else { - return SIGAR_OK; + return GetLastError(); } } diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 224edd40..ccbd4456 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -1434,20 +1434,18 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid, char cmdline[SIGAR_CMDLINE_MAX], *ptr = cmdline, *arg; HANDLE proc = open_process(pid); - if (!proc) { - return GetLastError(); + if (proc) { + status = sigar_proc_args_peb_get(sigar, proc, procargs); + + CloseHandle(proc); + + if (status == SIGAR_OK) { + return status; + } } - status = sigar_proc_args_peb_get(sigar, proc, procargs); - - CloseHandle(proc); - - if (status == ERROR_DATATYPE_MISMATCH) { - /* we are 32-bit, pid process is 64-bit */ - status = sigar_proc_args_wmi_get(sigar, pid, procargs); - } - - return status; + /* likely we are 32-bit, pid process is 64-bit */ + return sigar_proc_args_wmi_get(sigar, pid, procargs); } int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,