Memory leak with dev_add_pack()

Spiro Trikaliotis ml-kernelnewbies at
Fri Jan 21 15:54:02 EST 2011


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,
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:

   the correspondig Makefile is in

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

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 R. Trikaliotis                               

More information about the Kernelnewbies mailing list