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

Fixed resource leak in sootup.java.bytecode.frontend module #1099

Merged
merged 6 commits into from
Oct 25, 2024

Conversation

Bryce7832
Copy link
Contributor

@Bryce7832 Bryce7832 commented Oct 7, 2024

Fixed leak using try-with-resources. However, changed the method to return a List and do the collect operation inside the method to avoid try-with-resources closing the stream before its last use. This ensures the resources to be cleaned up. Fixes #1098

Copy link
Collaborator

@swissiety swissiety left a comment

Choose a reason for hiding this comment

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

thx for your contribution!

Comment on lines +170 to +171
.collect(Collectors.toList());
return javaSootClassSources.stream();
Copy link
Collaborator

@swissiety swissiety Oct 8, 2024

Choose a reason for hiding this comment

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

please don' t .collect() and .stream() again (return stream directly)

Copy link

Choose a reason for hiding this comment

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

Hi @swissiety since streams are lazy, if we don't collect, we cannot safely close the Stream returned by Files.walk within this method (since the filter and map operations won't have been executed yet). The collect forces those operations to execute, so then the stream can be closed. If you prefer not to collect and then stream again, an alternative would be to require all callers of this method to close the returned stream. Would that be preferable?

Copy link
Collaborator

Choose a reason for hiding this comment

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

thx @msridhar for pointing to that situation! As this is a protected method and its calling contexts are collecting the Stream again i would prefer to close the Stream in the two calling method(s) due to have less allocations

Choose a reason for hiding this comment

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

@Bryce7832 could you update the PR to get rid of the collect to a list, and instead use try-with-resources at both callers of this method?

@swissiety swissiety merged commit 4298c6e into soot-oss:develop Oct 25, 2024
7 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.

[Bug]: Resource Leak detected in sootup.java.bytecode.frontend module
3 participants