Skip to content

Commit

Permalink
perf expr: Fix missing check for return value of hashmap__new()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Yuuoniy authored and acmel committed Dec 18, 2021
1 parent 9eaa88c commit 0a515a0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/perf/util/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0a515a0

Please sign in to comment.