diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 28a74474ee8259129c524cd1aa1802e3c095eb7b..ab1a2870a3ed0fcd96bb90a5e881859bd71b5722 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1476,7 +1476,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, line = stat; - while (line) { + while (*line) { char *newLine = strchr(line, '\n'); char *valueStr = strchr(line, ' '); unsigned long long value; @@ -1506,6 +1506,11 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, inactiveFileVal = value >> 10; else if (STREQ(line, "unevictable")) unevictableVal = value >> 10; + + if (newLine) + line = newLine + 1; + else + break; } *cache = cacheVal; diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 32adb0678413fd11f06125da6a3dd19c14c2a57b..85aa62bd4cba2145333684cf569f0d99a0139716 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1068,7 +1068,7 @@ virCgroupV2GetMemoryStat(virCgroupPtr group, line = stat; - while (line) { + while (*line) { char *newLine = strchr(line, '\n'); char *valueStr = strchr(line, ' '); unsigned long long value; @@ -1102,6 +1102,11 @@ virCgroupV2GetMemoryStat(virCgroupPtr group, inactiveFileVal = value >> 10; else if (STREQ(line, "unevictable")) unevictableVal = value >> 10; + + if (newLine) + line = newLine + 1; + else + break; } *cache = cacheVal;