From: Long YunJian <long.yunj...@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.yunj...@zte.com.cn> Signed-off-by: Yi Wang <wang.y...@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; } /* We got jiffies -- 2.18.1