Memory leak with dev_add_pack()

Spiro Trikaliotis ml-kernelnewbies at spiro.trikaliotis.net
Fri Jan 21 15:54:02 EST 2011


Hello,

I have been tasked with writing a kernel module to handle an own
protocol (with an own EtherType) in the Linux kernel.

While I am not a complete newbie in the Linux kernel, having to handle
Ethernet traffic there is new to me.

I have looked at several tutorials and also at sample code (for example
http://www.phrack.org/archives/55/p55_0x0c_Building%20Into%20The%20Linux%20Network%20Layer_by_lifeline%20&%20kossak.txt,
and some tutorials I cannot find at the moment...) and tried to cut it
down to the bare essentials.

I came up with the following code utilising Linux Protocol Module:

   http://www.trikaliotis.net/testmodule/test_kernel.c

   the correspondig Makefile is in
   http://www.trikaliotis.net/testmodule/Makefile

Note: This is a cut-down version of the actual code which shows the
problem. Additionally, I register for ETH_P_ALL so the problem occurs as
fast as possible.

While it essentially works as I want it to, I found that I am leaking
memory this way. Having this module in a highly loaded network, 
"head -n5 /proc/meminfo" shows that MemFree is steadily falling, until
the kernel OOPS with an out of memory condition.

"Of course", if I undefine DO_MEMLEAK, the memory leak does not occur
anymore.

I tried for almost two weeks now to look at different tutorials, and I
also looked in working code (for example, the IP LPM) and tried to
compare with my code, but I could not find out what I am doing wrong
here. I am sure it must be something obvious, and very silly -
unfortunaely, for me, it is not obvious at the moment.

Can anyone help me here, please?

Best regards,
Spiro.

-- 
Spiro R. Trikaliotis                              http://opencbm.sf.net/
http://www.trikaliotis.net/                     http://www.viceteam.org/



More information about the Kernelnewbies mailing list