Free allocations according valgrind output. There is still a bit of problem with path_cpuset which return memory allocations on top of exiting allocations. Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- sys-utils/lscpu.c | 64 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 55 insertions(+), 9 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 224d5f9..9f43209 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -284,6 +284,8 @@ path_cpuset(const char *path, ...) set = path_cpuparse(0, path, ap); va_end(ap); + /* FIXME: cpu set memory allocations go on top of each + other which makes freeing at exit hard. */ return set; } @@ -360,16 +362,16 @@ read_basicinfo(struct lscpu_desc *desc) /* details */ while (fgets(buf, sizeof(buf), fp) != NULL) { /* IA64 */ - if (lookup(buf, "vendor", &desc->vendor)) ; - else if (lookup(buf, "vendor_id", &desc->vendor)) ; + if (!desc->vendor && lookup(buf, "vendor", &desc->vendor)) ; + else if (!desc->vendor && lookup(buf, "vendor_id", &desc->vendor)) ; /* IA64 */ - else if (lookup(buf, "family", &desc->family)) ; - else if (lookup(buf, "cpu family", &desc->family)) ; - else if (lookup(buf, "model", &desc->model)) ; - else if (lookup(buf, "stepping", &desc->stepping)) ; - else if (lookup(buf, "cpu MHz", &desc->mhz)) ; - else if (lookup(buf, "flags", &desc->flags)) ; - else if (lookup(buf, "bogomips", &desc->bogomips)) ; + else if (!desc->family && lookup(buf, "family", &desc->family)) ; + else if (!desc->family && lookup(buf, "cpu family", &desc->family)) ; + else if (!desc->model && lookup(buf, "model", &desc->model)) ; + else if (!desc->stepping && lookup(buf, "stepping", &desc->stepping)) ; + else if (!desc->mhz && lookup(buf, "cpu MHz", &desc->mhz)) ; + else if (!desc->flags && lookup(buf, "flags", &desc->flags)) ; + else if (!desc->bogomips && lookup(buf, "bogomips", &desc->bogomips)) ; else continue; } @@ -900,6 +902,48 @@ print_readable(struct lscpu_desc *desc, int hex) } } +void free_desc(struct lscpu_desc *desc) +{ + int i; + + free(desc->arch); + free(desc->bogomips); + free(desc->family); + free(desc->flags); + free(desc->mhz); + free(desc->model); + free(desc->stepping); + free(desc->vendor); + free(desc->virtflag); + + if (desc->coremaps) + free(desc->coremaps); + if (desc->online) + free(desc->online); + + for (i = 0; i < desc->nsockets; i++) + free(desc->socketmaps[i]); + if (desc->socketmaps) + free(desc->socketmaps); + + for (i = desc->ncaches - 1; i >= 0; i--) { + if (desc->caches[i].name) + free(desc->caches[i].name); + if (desc->caches[i].size) + free(desc->caches[i].size); + if (desc->caches[i].sharedmaps) + free(desc->caches[i].sharedmaps); + } + if (desc->caches) + free(desc->caches); + + for (i = 0; i < desc->nnodes; i++) { + free(desc->nodemaps[i]); + } + if (desc->nodemaps) + free(desc->nodemaps); +} + void usage(int rc) { printf(_("Usage: %s [option]\n"), @@ -974,5 +1018,7 @@ int main(int argc, char *argv[]) else print_readable(desc, hex); + free_desc(desc); + return EXIT_SUCCESS; } -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html