Skip to content

Commit

Permalink
[JENKINS-21229] Possible resource leak in parser
Browse files Browse the repository at this point in the history
- If an exception occurs before the stream is closed there will be a resource leak since close() won't be called.
- Solved using try-finally pattern.
- Indentation fixed.
  • Loading branch information
mixalturek committed Jan 5, 2014
1 parent 1c05513 commit 22fe900
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/hudson/plugins/sloccount/model/SloccountParser.java
Expand Up @@ -58,20 +58,25 @@ public SloccountReport parseFiles(java.io.File[] files) {

for (java.io.File file : files) {
try {
parse(file, report);
} catch (IOException e) {
// Silently ignore, there is still a possibility that other
// files can be parsed successfully
}
parse(file, report);
} catch (IOException e) {
// Silently ignore, there is still a possibility that other
// files can be parsed successfully
}
}

return report;
}

private void parse(java.io.File file, SloccountReportInterface report) throws IOException {
InputStreamReader in = new InputStreamReader(new FileInputStream(file), encoding);
this.parse(in, report);
in.close();
InputStreamReader in = null;

try {
in = new InputStreamReader(new FileInputStream(file), encoding);
this.parse(in, report);
} finally {
in.close();
}
}

private void parse(Reader reader, SloccountReportInterface report) throws IOException {
Expand Down

0 comments on commit 22fe900

Please sign in to comment.