diff options
author | Karel Zak | 2019-04-16 10:51:35 +0200 |
---|---|---|
committer | Karel Zak | 2019-04-16 10:51:35 +0200 |
commit | 7f8787d09405c7a8558f94d44186369422516a6f (patch) | |
tree | e2dc503b8b93063412d44c741a0171001ffa7236 /sys-utils/chcpu.c | |
parent | libmount: fix compiler warning [-Wsometimes-uninitialized] (diff) | |
download | kernel-qcow2-util-linux-7f8787d09405c7a8558f94d44186369422516a6f.tar.gz kernel-qcow2-util-linux-7f8787d09405c7a8558f94d44186369422516a6f.tar.xz kernel-qcow2-util-linux-7f8787d09405c7a8558f94d44186369422516a6f.zip |
chcpu: fix memory leak
The CPU set has been allocated more than once.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/chcpu.c')
-rw-r--r-- | sys-utils/chcpu.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c index 36c47affd..4060a4ca4 100644 --- a/sys-utils/chcpu.c +++ b/sys-utils/chcpu.c @@ -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); |