]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
ifindex: avoid memory allocation
authorEric Leblond <eric@inl.fr>
Mon, 2 Mar 2009 21:40:09 +0000 (22:40 +0100)
committerEric Leblond <eric@inl.fr>
Fri, 6 Mar 2009 19:31:23 +0000 (20:31 +0100)
This patch modifies the interp function to avoid to do an explicit
allocation of memory.

filter/ulogd_filter_IFINDEX.c

index f56ee0ba06411a6b685eb9d46cb5f5f259d6ee8d..152c26d09d1831f6a39fa4289ed9d159d1fdbf9c 100644 (file)
 static struct ulogd_key ifindex_keys[] = {
        { 
                .type = ULOGD_RET_STRING,
-               .flags = ULOGD_RETF_NONE | ULOGD_RETF_FREE,
+               .len = IFNAMSIZ,
+               .flags = ULOGD_RETF_NONE,
                .name = "oob.in", 
        },
        { 
                .type = ULOGD_RET_STRING,
-               .flags = ULOGD_RETF_NONE | ULOGD_RETF_FREE,
+               .len = IFNAMSIZ,
+               .flags = ULOGD_RETF_NONE,
                .name = "oob.out", 
        },
 };
@@ -62,25 +64,18 @@ static int interp_ifindex(struct ulogd_pluginstance *pi)
 {
        struct ulogd_key *ret = pi->output.keys;
        struct ulogd_key *inp = pi->input.keys;
-       void *ptr;
-
-       ptr = calloc(IFNAMSIZ, sizeof(char));
-       if (!ptr)
-               return ULOGD_IRET_ERR;
-
-       nlif_index2name(nlif_inst, ikey_get_u32(&inp[0]), ptr);
-       if (((char *)ptr)[0] == '*')
-               ((char *)(ptr))[0] = 0;
-       okey_set_ptr(&ret[0], ptr);
-
-       ptr = calloc(IFNAMSIZ, sizeof(char));
-       if (!ptr)
-               return ULOGD_IRET_ERR;
-
-       nlif_index2name(nlif_inst, ikey_get_u32(&inp[1]), ptr);
-       if (((char *)ptr)[0] == '*')
-               ((char *)(ptr))[0] = 0; 
-       okey_set_ptr(&ret[1], ptr);
+       static char indev[IFNAMSIZ];
+       static char outdev[IFNAMSIZ];
+
+       nlif_index2name(nlif_inst, ikey_get_u32(&inp[0]), indev);
+       if (indev[0] == '*')
+               indev[0] = 0;
+       okey_set_ptr(&ret[0], indev);
+
+       nlif_index2name(nlif_inst, ikey_get_u32(&inp[1]), outdev);
+       if (outdev[0] == '*')
+               outdev[0] = 0;
+       okey_set_ptr(&ret[1], outdev);
 
        return ULOGD_IRET_OK;
 }