]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chcpu: fix memory leak
authorKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2019 08:51:35 +0000 (10:51 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2019 08:51:35 +0000 (10:51 +0200)
The CPU set has been allocated more than once.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/chcpu.c

index 36c47affdcfb108c6dd56b2357e4392b12e04b80..4060a4ca4ac7d75527b546a87c0e51dc95c7fdef 100644 (file)
@@ -262,7 +262,7 @@ static void __attribute__((__noreturn__)) usage(void)
 int main(int argc, char *argv[])
 {
        struct path_cxt *sys = NULL;    /* _PATH_SYS_CPU handler */
-       cpu_set_t *cpu_set;
+       cpu_set_t *cpu_set = NULL;
        size_t setsize;
        int cmd = -1;
        int c, rc;
@@ -301,12 +301,13 @@ int main(int argc, char *argv[])
 
        if (ul_path_access(sys, F_OK, "online") == 0)
                ul_path_readf_cpulist(sys, &cpu_set, maxcpus, "online");
-
-       setsize = CPU_ALLOC_SIZE(maxcpus);
-       cpu_set = CPU_ALLOC(maxcpus);
+       else
+               cpu_set = CPU_ALLOC(maxcpus);
        if (!cpu_set)
                err(EXIT_FAILURE, _("cpuset_alloc failed"));
 
+       setsize = CPU_ALLOC_SIZE(maxcpus);
+
        while ((c = getopt_long(argc, argv, "c:d:e:g:hp:rV", longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);