Skip to content

Conversation

@Ayushd785
Copy link

*Description
Fixes a memory leak that occurred when netfilter hook registration failed
after creating the skb luadata object. In this case, the object was left
registered in Lua and never released.

The cleanup path now reliably releases the skb object, ensuring correct
resource management in all failure scenarios.

@Ayushd785
Copy link
Author

Hi @lneto, I hope you’re doing well.

I’ve been going through the codebase over the past few days and was looking for a small issue where I could contribute. This is my first PR, and it addresses a simple memory leak that occurred when netfilter hook registration failed after creating the skb luadata object.

I’d really appreciate any feedback or suggestions. I’ve enjoyed exploring the codebase and would love to continue contributing to Lunatik in the future.

{
luanetfilter_t *nf = (luanetfilter_t *)private;
if (nf->skb) {
luadata_close(nf->skb);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch =), but it seems that close() isn't the proper way to release this data object.. I think we would need a detach() that would work similarly to lunatik_unregister(), that's it, cleaning up the registry (w/ nil); then, the GC will collect it accordingly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right ,luadata_close() doesn’t remove the registry entry. I’ll add luadata_detach() (behaves like lunatik_unregisterobject()/sets registry entry to nil) so the GC can collect the object, then update the release path to use it.

static void luanetfilter_release(void *private)
{
luanetfilter_t *nf = (luanetfilter_t *)private;
if (nf->skb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move the attach() call to just after setting the runtime, so we won't need this verification; just the one below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay make sense, I’ll move luadata_attach() to just after lunatik_setruntime()

if (!nf->runtime)
return;

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you able to build it to 4.x? If I recall correctly we dropped support to kernel < 5.x. Perhaps it's the case of creating another PR removing the other similar ifdefs from this module..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README lists support for 5.x and 6.x. I can remove the 4.x #if and open a separate PR to clean up the remaining 4.x conditionals across the module unless you prefer they be included here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's perfect! thanks!

Copy link
Contributor

@lneto lneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheharyaar can you please take a look at this as well?

@lneto lneto requested a review from sheharyaar December 22, 2025 12:20
@lneto
Copy link
Contributor

lneto commented Dec 22, 2025

*Description Fixes a memory leak that occurred when netfilter hook registration failed after creating the skb luadata object. In this case, the object was left registered in Lua and never released.

It's not only when registration fails, right? The data object is never released if I got it correctly.

@lneto
Copy link
Contributor

lneto commented Dec 22, 2025

@Ayushd785 could you please also take a look at other places we are using luadata_attach()? including lneto_hid? thank you!

@sheharyaar
Copy link
Member

Sure, I am travelling today, I'll take a look at this tomorrow.

@Ayushd785
Copy link
Author

*Description Fixes a memory leak that occurred when netfilter hook registration failed after creating the skb luadata object. In this case, the object was left registered in Lua and never released.

It's not only when registration fails, right? The data object is never released if I got it correctly.

yes, nf->skb wasn’t released in luanetfilter_release() so it leaks on normal cleanup too.

@Ayushd785
Copy link
Author

@Ayushd785 could you please also take a look at other places we are using luadata_attach()? including lneto_hid? thank you!

absolutely, I’ll grep the repo for luadata_attach() uses and audit each release path (starting with luanetfilter.c and luaxtable.c)

@Ayushd785
Copy link
Author

hii, @lneto please allow me some time i'll work on the suggestions, i am still not very much comfortable with the repo i still need a study. Once i get the core, then i'll start contributing more confidently

@lneto
Copy link
Contributor

lneto commented Dec 23, 2025

hii, @lneto please allow me some time i'll work on the suggestions, i am still not very much comfortable with the repo i still need a study. Once i get the core, then i'll start contributing more confidently

of course, take your time =). thank you again!

@sheharyaar
Copy link
Member

Good catch @Ayushd785! I will test this patch, once I am free and update here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants