blktrace: Fix memleak problem in get_online_cpus()

lijinlin <[email protected]>
Newsgroups org.kernel.vger.linux-btrace
Message-ID <[email protected]>
From: lijinlin <[email protected]>

In get_online_cpus(), after cpu_nums is alloced memory successfully,
there are two return paths which don't free(cpu_nums).

Signed-off-by: lijinlin <[email protected]>
---
 blktrace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/blktrace.c b/blktrace.c
index 3444fbb..f1f646a 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -2759,6 +2759,7 @@ static cpu_set_t *get_online_cpus(void)
                while (prevcpuid <= cpuid) {
                        /* More CPUs listed than configured? */
                        if (curcpu >= ncpu) {
+                               free(cpu_nums);
                                errno = EINVAL;
                                return NULL;
                        }
@@ -2774,6 +2775,7 @@ static cpu_set_t *get_online_cpus(void)
        /* Now that we have maximum cpu number, create a cpuset */
        set = CPU_ALLOC(max_cpus);
        if (!set) {
+               free(cpu_nums);
                errno = ENOMEM;
                return NULL;
        }
--
2.23.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.