]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
perf expr: Fix missing check for return value of hashmap__new()
authorMiaoqian Lin <linmq006@gmail.com>
Sun, 12 Dec 2021 06:25:02 +0000 (06:25 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 18 Dec 2021 11:31:14 +0000 (08:31 -0300)
The hashmap__new() function may return ERR_PTR(-ENOMEM) when malloc()
fails, add IS_ERR() checking for ctx->ids.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.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/20211212062504.25841-1-linmq006@gmail.com
[ s/kfree()/free()/ and add missing linux/err.h include ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/expr.c

index 1d532b9fed29c2cf1349f5e730dfd5e77535a694..254601060b392c421a5e43f47c5403c99d074b6b 100644 (file)
@@ -12,6 +12,7 @@
 #include "expr-bison.h"
 #include "expr-flex.h"
 #include "smt.h"
+#include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 #include <ctype.h>
@@ -299,6 +300,10 @@ struct expr_parse_ctx *expr__ctx_new(void)
                return NULL;
 
        ctx->ids = hashmap__new(key_hash, key_equal, NULL);
+       if (IS_ERR(ctx->ids)) {
+               free(ctx);
+               return NULL;
+       }
        ctx->runtime = 0;
 
        return ctx;