Skip to content

Commit 0f03adc

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.16-2021-12-18' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix segfaults in 'perf inject' related to usage of unopened files - The return value of hashmap__new() should be checked using IS_ERR() * tag 'perf-tools-fixes-for-v5.16-2021-12-18' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf inject: Fix segfault due to perf_data__fd() without open perf inject: Fix segfault due to close without open perf expr: Fix missing check for return value of hashmap__new()
2 parents 9eaa88c + c271a55 commit 0f03adc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

tools/perf/builtin-inject.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,16 @@ static int parse_vm_time_correlation(const struct option *opt, const char *str,
755755
return inject->itrace_synth_opts.vm_tm_corr_args ? 0 : -ENOMEM;
756756
}
757757

758+
static int output_fd(struct perf_inject *inject)
759+
{
760+
return inject->in_place_update ? -1 : perf_data__fd(&inject->output);
761+
}
762+
758763
static int __cmd_inject(struct perf_inject *inject)
759764
{
760765
int ret = -EINVAL;
761766
struct perf_session *session = inject->session;
762-
struct perf_data *data_out = &inject->output;
763-
int fd = inject->in_place_update ? -1 : perf_data__fd(data_out);
767+
int fd = output_fd(inject);
764768
u64 output_data_offset;
765769

766770
signal(SIGINT, sig_handler);
@@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv)
10151019
}
10161020

10171021
inject.session = __perf_session__new(&data, repipe,
1018-
perf_data__fd(&inject.output),
1022+
output_fd(&inject),
10191023
&inject.tool);
10201024
if (IS_ERR(inject.session)) {
10211025
ret = PTR_ERR(inject.session);
@@ -1078,7 +1082,8 @@ int cmd_inject(int argc, const char **argv)
10781082
zstd_fini(&(inject.session->zstd_data));
10791083
perf_session__delete(inject.session);
10801084
out_close_output:
1081-
perf_data__close(&inject.output);
1085+
if (!inject.in_place_update)
1086+
perf_data__close(&inject.output);
10821087
free(inject.itrace_synth_opts.vm_tm_corr_args);
10831088
return ret;
10841089
}

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)