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

Using defer inside for loop could lead to leaks #121

Closed
wneessen opened this issue Mar 15, 2023 · 0 comments · Fixed by #122
Closed

Using defer inside for loop could lead to leaks #121

wneessen opened this issue Mar 15, 2023 · 0 comments · Fixed by #122
Assignees
Labels
bug Something isn't working

Comments

@wneessen
Copy link
Owner

Description

As mentioned in #116

you create resources inside for loop and defer inside for loop, the defer function will execute after function returns, so you won't be able to clean resources inside for loop, it all will wait until function exists. I put close after for loop ended. so it will release the resources after for loop ends.

The initial author doesn't found the time to fix this completely, so this issue is meant to address the issue.

To Reproduce

N/A

Expected behaviour

N/A

Screenshots

No response

Attempted Fixes

No response

Additional context

No response

@wneessen wneessen added the bug Something isn't working label Mar 15, 2023
@wneessen wneessen self-assigned this Mar 15, 2023
wneessen added a commit that referenced this issue Mar 15, 2023
Fixes #121. `defer` in for loops can possibly lead to leaks.

The whole handling including the defer are now moved into anonymous functions outside the for loop and are called form the loop instead. This way the defer is handle when the inline function finishes
@wneessen wneessen linked a pull request Mar 15, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant