
[snip]
for (i = 0; i < *nparams; i++) { virNodeCPUStatsPtr param = ¶ms[i];
What about this?
diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 1838547..aa1ad81 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -637,8 +637,9 @@ linuxNodeGetCPUStats(FILE *procstat,
while (fgets(line, sizeof(line), procstat) != NULL) { char *buf = line; + char **buf_header = virStringSplit(buf, " ", 2);
- if (STRPREFIX(buf, cpu_header)) { /* aka logical CPU time */ + if (STREQ(buf_header[0], cpu_header)) { /* aka logical CPU time */ size_t i;
if (sscanf(buf, @@ -697,6 +698,7 @@ linuxNodeGetCPUStats(FILE *procstat, ret = 0; goto cleanup; } + virStringFreeList(buf_header); }
virReportInvalidArg(cpuNum,
This is definitely better and lesser amount of code..
I think the version with virStringSplit would need some fine tuning since in its current form it will not free the memory for the failure cases..Comments ? Also can some expert here provide some tips on whether in this particular circumstance it should be fine to allocate/realloc/free memory inside the while loop. Would be very helpful.. Thanks, Pradipta
Thanks
-- 1.8.3.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list