lkml.org 
[lkml]   [2021]   [Dec]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] perf expr: Fix missing check for return value of hashmap__new
Date
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>
---
tools/perf/util/expr.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
index 1d532b9fed29..c94c9ea30d1a 100644
--- a/tools/perf/util/expr.c
+++ b/tools/perf/util/expr.c
@@ -299,6 +299,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)) {
+ kfree(ctx);
+ return NULL;
+ }
ctx->runtime = 0;

return ctx;
--
2.17.1
\
 
 \ /
  Last update: 2021-12-12 07:26    [W:0.042 / U:0.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site