Skip to content

Fix resource leak in ioStreamRead useNIO branch#1736

Merged
nmaguiar merged 2 commits intot8from
copilot/sub-pr-1735
Mar 4, 2026
Merged

Fix resource leak in ioStreamRead useNIO branch#1736
nmaguiar merged 2 commits intot8from
copilot/sub-pr-1735

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

reader.close() in the useNIO path of ioStreamRead was only reached on normal exit or early-return — any exception thrown by reader.read(...) or aFunction(...) would silently leak the reader and its underlying stream.

Change

Replaced the two explicit reader.close() calls with a single try/finally block, guaranteeing closure on all exit paths:

try {
    while ((nRead = reader.read(cbuf, 0, bufferSize)) > 0) {
        var res = aFunction(String(new java.lang.String(cbuf, 0, nRead)));
        if (res == true) {
            return;
        }
    }
} finally {
    reader.close();
}

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI mentioned this pull request Mar 4, 2026
Merged
Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback from PR #1735 review discussion Fix resource leak in ioStreamRead useNIO branch Mar 4, 2026
@nmaguiar nmaguiar marked this pull request as ready for review March 4, 2026 22:45
@nmaguiar nmaguiar merged commit 4a79494 into t8 Mar 4, 2026
1 check passed
@nmaguiar nmaguiar deleted the copilot/sub-pr-1735 branch March 4, 2026 22:45
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