Skip to content

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

Merged
swissiety merged 6 commits intosoot-oss:developfrom
Bryce7832:bug/resourceleak_bytecode
Oct 25, 2024
Merged

Fixed resource leak in sootup.java.bytecode.frontend module#1099
swissiety merged 6 commits intosoot-oss:developfrom
Bryce7832:bug/resourceleak_bytecode

Conversation

@Bryce7832
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

Copy link
Copy Markdown

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 force-pushed the bug/resourceleak_bytecode branch from 3f25697 to 5b55176 Compare October 25, 2024 11:45
@swissiety swissiety force-pushed the bug/resourceleak_bytecode branch from 5b55176 to a7bb4f8 Compare October 25, 2024 11:49
@swissiety swissiety merged commit 4298c6e into soot-oss:develop Oct 25, 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.

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

3 participants