Messages in this thread Patch in this message | | | From | Chen Wandun <> | Subject | [PATCH next v2 1/2] perf tools: fix potential memleak in perf events parser | Date | Thu, 11 Jun 2020 22:56:04 +0800 |
| |
From: Cheng Jian <cj.chengjian@huawei.com>
Fix memory leak of in function parse_events_term__sym_hw() and parse_events_term__clone() when error occur.
Fixes: b6645a723595 ("perf parse: Ensure config and str in terms are unique") Signed-off-by: Cheng Jian <cj.chengjian@huawei.com> Signed-off-by: Chen Wandun <chenwandun@huawei.com> --- tools/perf/util/parse-events.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 3decbb203846..6f4dc8a92817 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2957,8 +2957,12 @@ int parse_events_term__sym_hw(struct parse_events_term **term, sym = &event_symbols_hw[idx]; str = strdup(sym->symbol); - if (!str) + if (!str) { + if (!config) + free(temp.config); return -ENOMEM; + } + return new_term(term, &temp, str, 0); } @@ -2983,8 +2987,12 @@ int parse_events_term__clone(struct parse_events_term **new, return new_term(new, &temp, NULL, term->val.num); str = strdup(term->val.str); - if (!str) + if (!str) { + if (term->config) + free(temp.config); return -ENOMEM; + } + return new_term(new, &temp, str, 0); } -- 2.17.1
| |