On Wed, Dec 04, 2019 at 05:06:07PM -0800, Yonghong Song wrote: > > - obj = bpf_object__open_file("./fexit_bpf2bpf.o", &opts); > + obj = bpf_object__open_file(obj_file, &opts); > if (CHECK(IS_ERR_OR_NULL(obj), "obj_open", > "failed to open fexit_bpf2bpf: %ld\n", > PTR_ERR(obj))) > @@ -38,7 +34,14 @@ void test_fexit_bpf2bpf(void) > if (CHECK(err, "obj_load", "err %d\n", err)) > goto close_prog; > > - for (i = 0; i < PROG_CNT; i++) { > + link = calloc(sizeof(struct bpf_link *), prog_cnt); > + prog = calloc(sizeof(struct bpf_program *), prog_cnt); > + result = malloc(prog_cnt * sizeof(u64)); > + if (CHECK(!link || !prog || !result, "alloc_memory", > + "failed to alloc memory")) > + goto close_prog; bpf_object__open_file() can fail when jit is off and for() loop in close_prog will segfault. I fixed it up by moving above 3 mallocs before bpf_object__open_file() and applied both patches. Thanks!