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: explicitly close ctmap on every iteration #4

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from

Conversation

fstr
Copy link
Collaborator

@fstr fstr commented Jun 24, 2024

Description

Explicitly close m after every iteration, because defer m.Close() will only close it when the function returns. This means as long as the loop is running, the callstack increases.

Other notes to the reviewer

I aim to close a potential memory leak

@fstr fstr force-pushed the fstr/close_ctmap branch from db20dce to 88706fe Compare June 24, 2024 13:48
@@ -77,8 +76,12 @@ func listRecords(maps []interface{}, clockSource ClockSource, filter EntriesFilt
}
}
if err = m.DumpWithCallback(cb); err != nil {
m.Close()
Copy link

@artem-ag artem-ag Jun 24, 2024

Choose a reason for hiding this comment

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

Consider moving cb := definition outside of for-loop as it does not appear to depend on m (therefore no need to create a new function every iteration). And moving whatever remains into a separate function that could retain defer m.Close().

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