Skip to content

Commit 0a515a0

Browse files
Yuuoniyacmel
authored andcommitted
perf expr: Fix missing check for return value of hashmap__new()
The hashmap__new() function may return ERR_PTR(-ENOMEM) when malloc() fails, add IS_ERR() checking for ctx->ids. Signed-off-by: Miaoqian Lin <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] [ s/kfree()/free()/ and add missing linux/err.h include ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9eaa88c commit 0a515a0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/perf/util/expr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "expr-bison.h"
1313
#include "expr-flex.h"
1414
#include "smt.h"
15+
#include <linux/err.h>
1516
#include <linux/kernel.h>
1617
#include <linux/zalloc.h>
1718
#include <ctype.h>
@@ -299,6 +300,10 @@ struct expr_parse_ctx *expr__ctx_new(void)
299300
return NULL;
300301

301302
ctx->ids = hashmap__new(key_hash, key_equal, NULL);
303+
if (IS_ERR(ctx->ids)) {
304+
free(ctx);
305+
return NULL;
306+
}
302307
ctx->runtime = 0;
303308

304309
return ctx;

0 commit comments

Comments
 (0)