]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: cleaup arch freeing
authorKarel Zak <kzak@redhat.com>
Thu, 14 May 2020 10:02:44 +0000 (12:02 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 08:19:02 +0000 (09:19 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-api.h
sys-utils/lscpu-cputype.c
sys-utils/lscpu-virt.c

index a06ec81916fc1c236bcb49841cb20cdd53857909..9bbd18d2431c7e406f44473503a53cfa32dd7d7b 100644 (file)
@@ -172,14 +172,16 @@ struct lscpu_cputype *lscpu_add_cputype(struct lscpu_cxt *cxt, struct lscpu_cput
 struct lscpu_cputype *lscpu_cputype_get_default(struct lscpu_cxt *cxt);
 
 int lscpu_read_cpuinfo(struct lscpu_cxt *cxt);
-int lscpu_read_architecture(struct lscpu_cxt *cxt);
 int lscpu_read_cpulists(struct lscpu_cxt *cxt);
 int lscpu_read_extra(struct lscpu_cxt *cxt);
 int lscpu_read_vulnerabilities(struct lscpu_cxt *cxt);
 int lscpu_read_numas(struct lscpu_cxt *cxt);
 
+struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt);
+void lscpu_free_architecture(struct lscpu_arch *ar);
+
 struct lscpu_virt *lscpu_read_virtualization(struct lscpu_cxt *cxt);
-void lscpu_free_virt(struct lscpu_virt *virt);
+void lscpu_free_virtualization(struct lscpu_virt *virt);
 
 struct lscpu_cpu *lscpu_new_cpu(void);
 void lscpu_ref_cpu(struct lscpu_cpu *cpu);
index 02ef452ad6e147524e38ea3db90e6d3c220124c5..dfa539b6ea5f7751cd039609616ba919c8f4c05d 100644 (file)
@@ -410,21 +410,20 @@ int lscpu_read_cpuinfo(struct lscpu_cxt *cxt)
        return 0;
 }
 
-int lscpu_read_architecture(struct lscpu_cxt *cxt)
+struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt)
 {
        struct utsname utsbuf;
        struct lscpu_arch *ar;
        struct lscpu_cputype *ct;
 
        assert(cxt);
-       assert(!cxt->arch);
 
-       DBG(GATHER, ul_debugobj(cxt, "reading architecture"));
+       DBG(GATHER, ul_debug("reading architecture"));
 
        if (uname(&utsbuf) == -1)
                err(EXIT_FAILURE, _("error: uname failed"));
 
-       ar = cxt->arch = xcalloc(1, sizeof(*cxt->arch));
+       ar = xcalloc(1, sizeof(*cxt->arch));
        ar->name = xstrdup(utsbuf.machine);
 
        if (cxt->noalive)
@@ -476,7 +475,19 @@ int lscpu_read_architecture(struct lscpu_cxt *cxt)
                        ar->bit32 = 1;
        }
 
-       return 0;
+       DBG(GATHER, ul_debugobj(ar, "arch: name=%s %s %s",
+                               ar->name,
+                               ar->bit64 ? "64-bit" : "",
+                               ar->bit64 ? "32-bit" : ""));
+       return ar;
+}
+
+void lscpu_free_architecture(struct lscpu_arch *ar)
+{
+       if (!ar)
+               return;
+       free(ar->name);
+       free(ar);
 }
 
 int lscpu_read_cpulists(struct lscpu_cxt *cxt)
@@ -759,9 +770,6 @@ void lscpu_free_context(struct lscpu_cxt *cxt)
        free(cxt->idx2cpunum);
        free(cxt->present);
        free(cxt->online);
-       if (cxt->arch)
-               free(cxt->arch->name);
-       free(cxt->arch);
        free(cxt->cputypes);
        free(cxt->cpus);
 
@@ -777,7 +785,8 @@ void lscpu_free_context(struct lscpu_cxt *cxt)
        free(cxt->nodemaps);
        free(cxt->idx2nodenum);
 
-       lscpu_free_virt(cxt->virt);
+       lscpu_free_virtualization(cxt->virt);
+       lscpu_free_architecture(cxt->arch);
 
        free(cxt);
 }
@@ -797,7 +806,8 @@ int main(int argc, char **argv)
        context_init_paths(cxt);
 
        lscpu_read_cpuinfo(cxt);
-       lscpu_read_architecture(cxt);
+       cxt->arch = lscpu_read_architecture(cxt);
+
        lscpu_read_cpulists(cxt);
        lscpu_read_extra(cxt);
        lscpu_read_vulnerabilities(cxt);
index 68c01fcda781315a173eebfa38e0bc81024e7b3b..501e4f8ebbe0d94f32f8e80807aac6cb588b2b21 100644 (file)
@@ -732,7 +732,7 @@ done:
        return virt;
 }
 
-void lscpu_free_virt(struct lscpu_virt *virt)
+void lscpu_free_virtualization(struct lscpu_virt *virt)
 {
        if (!virt)
                return;