gamemann / XDP-Firewall

A firewall that utilizes the Linux kernel's XDP hook. The XDP hook allows for very fast network processing on Linux systems. This is great for dropping malicious traffic from a (D)DoS attack. IPv6 is supported with this firewall! I hope this helps network engineers/programmers interested in utilizing XDP!
https://deaconn.net/
MIT License
492 stars 87 forks source link

Mem Leak #32

Closed Nasty07 closed 1 year ago

Nasty07 commented 1 year ago

Hello and thank you for this project. It has helped me a lot to understand XDP and move forward with my own version. After testing for mem leaks using Valgrind, I think that readcfg() is leaking. What are your thoughts?

==19146== 10,425 bytes in 2,085 blocks are definitely lost in loss record 11 of 11 ==19146== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==19146== by 0x494238E: strdup (strdup.c:42) ==19146== by 0x41DCF7: readcfg (in /usr/bin/xdpfw) ==19146== by 0x41EB93: updateconfig (in /usr/bin/xdpfw) ==19146== by 0x4200E9: main (in /usr/bin/xdpfw)

Full log attached valgrind.log

Nasty07 commented 1 year ago

The leak comes from config.c:156 cfg->interface = strdup(interface);

Maybe we need to free() the return value before updating it again?

Nasty07 commented 1 year ago

Possible fix in #33

gamemann commented 1 year ago

Looks good! Thank you for the help :)

gamemann commented 1 year ago

I am going to close this for now since I merged the PR. Feel free to reopen if needed!

Also, no problem on creating the project. I'm just glad it helps others with XDP and such.