map: make a helper function for freeing entries
authorFelix Fietkau <nbd@nbd.name>
Wed, 3 Nov 2021 10:13:53 +0000 (11:13 +0100)
committerFelix Fietkau <nbd@nbd.name>
Wed, 3 Nov 2021 10:13:53 +0000 (11:13 +0100)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
map.c

diff --git a/map.c b/map.c
index 636a46be2816ea35806b193a6e68deec40ed6e5f..2eacfcdc40b67ac391913aef7bd798b4da3bcfb1 100644 (file)
--- a/map.c
+++ b/map.c
@@ -506,12 +506,20 @@ void qosify_map_reload(void)
        qosify_map_gc();
 }
 
+static void qosify_map_free_entry(struct qosify_map_entry *e)
+{
+       int fd = qosify_map_fds[e->data.id];
+
+       avl_delete(&map_data, &e->avl);
+       bpf_map_delete_elem(fd, &e->data.addr);
+       free(e);
+}
+
 void qosify_map_gc(void)
 {
        struct qosify_map_entry *e, *tmp;
        int32_t timeout = 0;
        uint32_t cur_time = qosify_gettime();
-       int fd;
 
        next_timeout = 0;
        avl_for_each_element_safe(&map_data, e, avl, tmp) {
@@ -531,10 +539,7 @@ void qosify_map_gc(void)
                if (e->data.file || e->data.user)
                        continue;
 
-               avl_delete(&map_data, &e->avl);
-               fd = qosify_map_fds[e->data.id];
-               bpf_map_delete_elem(fd, &e->data.addr);
-               free(e);
+               qosify_map_free_entry(e);
        }
 
        if (!timeout)