From: Masatake YAMATO Date: Tue, 26 Sep 2023 16:04:54 +0000 (+0900) Subject: tests: (test_mkfds::{bpf-prog,bpf-map}) fix memory leaks X-Git-Tag: v2.40-rc1~224^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f5dcdeb7a783e2ec596b638044d4b2d2d0e62f40;p=thirdparty%2Futil-linux.git tests: (test_mkfds::{bpf-prog,bpf-map}) fix memory leaks Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index 05931967c2..db61727e2c 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -2852,6 +2852,9 @@ static void *make_bpf_prog(const struct factory *factory, struct fdesc fdescs[], struct arg prog_type_id = decode_arg("prog-type-id", factory->params, argc, argv); int iprog_type_id = ARG_INTEGER(prog_type_id); + struct arg name = decode_arg("name", factory->params, argc, argv); + const char *sname = ARG_STRING(name); + int bfd; union bpf_attr attr; /* Just doing exit with 0. */ @@ -2866,12 +2869,15 @@ static void *make_bpf_prog(const struct factory *factory, struct fdesc fdescs[], }, }; - memset(&attr, 0, sizeof(attr)); attr.prog_type = iprog_type_id; attr.insns = (uint64_t)(unsigned long)insns; attr.insn_cnt = ARRAY_SIZE(insns); attr.license = (int64_t)(unsigned long)"GPL"; + strncpy(attr.prog_name, sname, sizeof(attr.prog_name) - 1); + + free_arg(&name); + free_arg(&prog_type_id); bfd = syscall(SYS_bpf, BPF_PROG_LOAD, &attr, sizeof(attr)); if (bfd < 0) @@ -2959,6 +2965,9 @@ static void *make_bpf_map(const struct factory *factory, struct fdesc fdescs[], struct arg map_type_id = decode_arg("map-type-id", factory->params, argc, argv); int imap_type_id = ARG_INTEGER(map_type_id); + struct arg name = decode_arg("name", factory->params, argc, argv); + const char *sname = ARG_STRING(name); + int bfd; union bpf_attr attr = { .map_type = imap_type_id, @@ -2967,6 +2976,11 @@ static void *make_bpf_map(const struct factory *factory, struct fdesc fdescs[], .max_entries = 10, }; + strncpy(attr.map_name, sname, sizeof(attr.map_name) - 1); + + free_arg(&name); + free_arg(&map_type_id); + bfd = syscall(SYS_bpf, BPF_MAP_CREATE, &attr, sizeof(attr)); if (bfd < 0) err((errno == ENOSYS? EXIT_ENOSYS: EXIT_FAILURE), @@ -3739,6 +3753,12 @@ static const struct factory factories[] = { .desc = "program type by id", .defv.integer = 1, }, + { + .name = "name", + .type = PTYPE_STRING, + .desc = "name assigned to bpf prog object", + .defv.string = "mkfds_bpf_prog", + }, PARAM_END } }, @@ -3767,6 +3787,12 @@ static const struct factory factories[] = { .desc = "map type by id", .defv.integer = 1, }, + { + .name = "name", + .type = PTYPE_STRING, + .desc = "name assigned to the bpf map object", + .defv.string = "mkfds_bpf_map", + }, PARAM_END } },