Skip to content

fix: Memory leak caused by openFile and osOpen functions #102

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

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

oliveromahony
Copy link
Contributor

@oliveromahony oliveromahony commented Jul 4, 2024

Proposed changes

The parse function was leaking memory. On analysis of the code it looked like the fileOpen function was keeping the memory active, after the file was being used.

  • Changed the io.Reader to io.ReadCloser in Open signature
  • Changed the io.Reader to io.ReadCloser in osOpen signature
  • Added defer to close the file after function exit in Parse

A snapshot of the memory in the NGINX Agent before these changes:
image

and after:
image

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING document
  • If applicable, I have added tests that prove my fix is effective or that my feature works
  • If applicable, I have checked that any relevant tests pass after adding my changes
  • I have updated any relevant documentation (README.md)

…t looked like the fileOpen function was keeping the memory active, after the file was being used. Changed the io.Reader to io.ReadCloser and defer closed the file after function exit
@oliveromahony oliveromahony requested a review from a team as a code owner July 4, 2024 14:44
@oliveromahony oliveromahony requested a review from valyria257 July 4, 2024 15:08
Copy link
Member

@ornj ornj left a comment

Choose a reason for hiding this comment

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

Can you also remove this type assertion block? I think it is no longer needed now that the correct type is passed.

@oliveromahony oliveromahony merged commit 10437d9 into main Jul 9, 2024
2 checks passed
@oliveromahony oliveromahony deleted the memory-leak branch July 9, 2024 09:26
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.

3 participants