]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (test_mkfds::{bpf-prog,bpf-map}) fix memory leaks
authorMasatake YAMATO <yamato@redhat.com>
Tue, 26 Sep 2023 16:04:54 +0000 (01:04 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 29 Sep 2023 20:29:15 +0000 (05:29 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_mkfds.c

index 05931967c26d8f959c4dc2cc69506d488123f15e..db61727e2c5386e758497b8982e7b88780f4074e 100644 (file)
@@ -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
                }
        },