Skip to content

fix: close InputStream from Profile.assets() in PfShell.key() - #2

Open
imedfan wants to merge 2 commits into
masterfrom
fix/2324-pfshell-stream-leak
Open

fix: close InputStream from Profile.assets() in PfShell.key()#2
imedfan wants to merge 2 commits into
masterfrom
fix/2324-pfshell-stream-leak

Conversation

@imedfan

@imedfan imedfan commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the resource leak described in yegor256#2324.

PfShell.key() retrieved the SSH private key from Profile.assets() without closing the returned InputStream. It also called assets().get(path) twice — once for the null check and once to read the stream — so neither stream was closed. Since Profile.assets() returns raw streams owned by the caller and IOUtils.toString() does not close them, this leaked file descriptors / memory.

Changes

  • Wrap the asset stream in a try-with-resources block for deterministic closure.
  • Fetch the stream only once instead of twice.
  • Perform the null check on the single fetched stream.

Profile.ConfigException extends RuntimeException, so the not-found exception still propagates without being re-wrapped by the IOException catch — behavior is preserved.

Test plan

  • mvn compile succeeds.
  • Existing CI suite passes.

https://claude.ai/code/session_01JMZzw7mA6JumUiPuS8QEMb


Generated by Claude Code

claude added 2 commits May 21, 2026 22:12
Wrap the asset stream in a try-with-resources block so the
InputStream returned by Profile.assets().get(path) is closed
deterministically, and fetch it only once instead of twice.

https://claude.ai/code/session_01JMZzw7mA6JumUiPuS8QEMb
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