From 411da4d946a68d59005fece7fcdb0c48a228166b Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 2 Mar 2009 22:40:09 +0100 Subject: ifindex: avoid memory allocation This patch modifies the interp function to avoid to do an explicit allocation of memory. --- filter/ulogd_filter_IFINDEX.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'filter') diff --git a/filter/ulogd_filter_IFINDEX.c b/filter/ulogd_filter_IFINDEX.c index f56ee0b..152c26d 100644 --- a/filter/ulogd_filter_IFINDEX.c +++ b/filter/ulogd_filter_IFINDEX.c @@ -30,12 +30,14 @@ 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; } -- cgit v1.2.3