mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-04 16:15:11 +00:00
perf c2c: Prevent potential memory leak in c2c_he_zalloc()
Free allocated resources when zalloc() fails for members in c2c_he, to prevent potential memory leak in c2c_he_zalloc(). Signed-off-by: Shang XiaoJing <shangxiaojing@huawei.com> Reviewed-by: Leo Yan <leo.yan@linaro.org> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20220906032906.21395-4-shangxiaojing@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
6ea9da51a5
commit
4efa8e3143
1 changed files with 9 additions and 3 deletions
|
@ -146,15 +146,15 @@ static void *c2c_he_zalloc(size_t size)
|
|||
|
||||
c2c_he->cpuset = bitmap_zalloc(c2c.cpus_cnt);
|
||||
if (!c2c_he->cpuset)
|
||||
return NULL;
|
||||
goto out_free;
|
||||
|
||||
c2c_he->nodeset = bitmap_zalloc(c2c.nodes_cnt);
|
||||
if (!c2c_he->nodeset)
|
||||
return NULL;
|
||||
goto out_free;
|
||||
|
||||
c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
|
||||
if (!c2c_he->node_stats)
|
||||
return NULL;
|
||||
goto out_free;
|
||||
|
||||
init_stats(&c2c_he->cstats.lcl_hitm);
|
||||
init_stats(&c2c_he->cstats.rmt_hitm);
|
||||
|
@ -163,6 +163,12 @@ static void *c2c_he_zalloc(size_t size)
|
|||
init_stats(&c2c_he->cstats.load);
|
||||
|
||||
return &c2c_he->he;
|
||||
|
||||
out_free:
|
||||
free(c2c_he->nodeset);
|
||||
free(c2c_he->cpuset);
|
||||
free(c2c_he);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void c2c_he_free(void *he)
|
||||
|
|
Loading…
Reference in a new issue