Skip to content

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