Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set 'elf' to nil after closing in BPFLoadObject for GC #451

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

rscampos
Copy link
Collaborator

In the BPFLoadObject function, the 'elf' field is closed, but it is not set to nil. Setting it to nil is necessary for it to be freed by the garbage collector.

In the BPFLoadObject function, the 'elf' field is closed, but
it is not set to nil. Setting it to nil is necessary for it to
be freed by the garbage collector.
@rscampos rscampos requested a review from geyslan July 26, 2024 21:20
@rscampos
Copy link
Collaborator Author

In order to test this commit, use the following snip before and after BPFLoadObject():

var memBefore runtime.MemStats
runtime.ReadMemStats(&memBefore)
fmt.Println("Alloc mem before: ", memBefore.Alloc)

Some results:
Without this commit:

sudo ./run.sh main-static
Memory stats before:
Alloc = 85952 bytes
Memory stats after:
Alloc = 85984 bytes

With this commit:

sudo ./run.sh main-static
Memory stats before:
Alloc = 85952 bytes
Memory stats after:
Alloc = 80144 bytes

Copy link
Member

@geyslan geyslan left a comment

Choose a reason for hiding this comment

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

Good catch. ❤️ It seems safe to nullify it since m.loaded is checked first in the related logics.

@rscampos rscampos merged commit 61d531a into aquasecurity:main Jul 29, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants