nlif_open() - nlif_close() - memory leak?
Hello!
Just doing some testuing of NFQUEUE, and noticed that in the simple case, if I do the following (yes, there is no "nlif_catch", but anyway) - I'm experiencing a memory leak for every open - close cycle?
Anything I'm missing?
struct nlif_handle *h;
h = nlif_open();
if (h != NULL) {
nlif_query(h);
nfq_get_indev_name(h,tb,agg.iname);
nfq_get_outdev_name(h,tb,agg.oname);
nlif_close(h);
}Hello,
Quoted 8 lines · Anton
Hello!
Just doing some testuing of NFQUEUE, and noticed that in the simple case, if I do the following (yes, there is no "
nlif_catch", but anyway) - I'm experiencing a memory leak for every open - close cycle?
Anything I'm missing?
Quoted 8 lines
struct nlif_handle *h;
h = nlif_open();
if (h != NULL) {
nlif_query(h);
nfq_get_indev_name(h,tb,agg.iname);
nfq_get_outdev_name(h,tb,agg.oname);
nlif_close(h);
}You should not call nlif_open, nlif_close at each resolution:
Information about nlif usage:
http://software.inl.fr/trac/wiki/articles/using_nlif
Anyway, I will investigate to see what's going on. We definitely should not have a memory leak.
BR,
Signature · 3 lines
Eric Leblond INL: http://www.inl.fr/ NuFW: http://www.nufw.org/
Quoted 5 lines · Eric Leblond
Hello,
On Thursday, 2008 May 22 at 10:53:40 +0500, Anton wrote:
You should not callnlif_open,nlif_closeat each resolution:
Yes, this is obvious, it was just a quick test.
Quoted 3 lines
Information about nlif usage:
http://software.inl.fr/trac/wiki/articles/using_nlif
Great, thanks!
Quoted 5 lines
Anyway, I will investigate to see what's going on. We definitely should not have a memory leak.
BR,
Hello,
Quoted 7 lines · Anton
Quoted 5 lines · Eric Leblond
Hello,
On Thursday, 2008 May 22 at 10:53:40 +0500, Anton wrote:
You should not callnlif_open,nlif_closeat each resolution:
Quoted 11 lines
Yes, this is obvious, it was just a quick test.
Quoted 3 lines
Information about nlif usage:
http://software.inl.fr/trac/wiki/articles/using_nlifGreat, thanks!
Quoted 3 lines
Anyway, I will investigate to see what's going on. We definitely should not have a memory leak.
The attached patch should fix the memory leak issue. Could you test it ?
BR,
Signature · 3 lines
Eric Leblond INL: http://www.inl.fr/ NuFW: http://www.nufw.org/
src/iftable.c +17 -1
@@ -25,6 +25,8 @@#define iftb_log (x, ...) +#define SIZE_IFHASH 16 +struct ifindex_map {struct ifindex_map *next;
@@ -37,7 +39,7 @@ struct ifindex_map { };struct nlif_handle { -struct ifindex_map *ifindex_map[16 ]; +struct ifindex_map *ifindex_map[SIZE_IFHASH ];struct rtnl_handle *rtnl_handle;struct rtnl_handler ifadd_handler;struct rtnl_handler ifdel_handler;
@@ -255,6 +257,19 @@ err:return NULL ; } +static void free_indexmap (struct ifindex_map **indexmap) +{ +struct ifindex_map *im, *ima, **imp; +int i; + +for (i =0 ; i <SIZE_IFHASH ; i++) { +for (ima =NULL , imp = &(indexmap[i]); + (im=*imp)!=NULL ; imp = &im->next, ima=im) { +free (ima); + } + } +} +/** Destructor of interface table * * \param nlif_handle A pointer to a ::nlif_handle created
@@ -267,6 +282,7 @@ void nlif_close(struct nlif_handle *h)rtnl_handler_unregister (h->rtnl_handle, &h->ifadd_handler);rtnl_handler_unregister (h->rtnl_handle, &h->ifdel_handler);rtnl_close (h->rtnl_handle); +free_indexmap (h->ifindex_map);free (h); h =NULL ;/* bugtrap */ }