On 7/15/21 8:18 AM, Yi Wang wrote:
From: Long YunJian <long.yunjian@zte.com.cn>
If fscanf execute failed, qemuGetProcessInfo shuld return -1,
but it return 0 at the end. Zero means success for the caller,
so we shuld return -1 in the case of failure.
Signed-off-by: Long YunJian <long.yunjian@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
src/qemu/qemu_driver.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index df44c3fbd0..4c3785fa36 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1442,11 +1442,13 @@ qemuGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_rss,
return -1;
pidinfo = fopen(proc, "r");
+ if (!pidinfo) {
+ return -1;
+ }
/* See 'man proc' for information about what all these fields are. We're
* only interested in a very few of them */
- if (!pidinfo ||
- fscanf(pidinfo,
+ if (fscanf(pidinfo,
/* pid -> stime */
"%*d (%*[^)]) %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu"
/* cutime -> endcode */
@@ -1455,6 +1457,8 @@ qemuGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_rss,
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d",
&usertime, &systime, &rss, &cpu) != 4) {
VIR_WARN("cannot parse process status data");
+ VIR_FORCE_FCLOSE(pidinfo);
+ return -1;
There's another VIR_FORCE_FCLOSE() at the end of the function. It should
be removed.
But is there an actual error you're seeing? Has /proc/NNN/stat format
changed? Also, please use git send-email if possible - it allows
reviewers to use git am (which doesn't work with multipart e-mails).
Michal