mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
fixed a file handle leak
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11312 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
9c570173c1
commit
8464ea0fdb
1 file changed
+13
-9
@@ -924,15 +924,19 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
|
||||
int lineCount = 0;
|
||||
List<String> logLines = new LinkedList<String>();
|
||||
BufferedReader reader = new BufferedReader(new FileReader(getLogFile()));
|
||||
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
|
||||
logLines.add(line);
|
||||
++lineCount;
|
||||
// If we have too many lines, remove the oldest line. This way we
|
||||
// never have to hold the full contents of a huge log file in memory.
|
||||
// Adding to and removing from the ends of a linked list are cheap
|
||||
// operations.
|
||||
if (lineCount > maxLines)
|
||||
logLines.remove(0);
|
||||
try {
|
||||
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
|
||||
logLines.add(line);
|
||||
++lineCount;
|
||||
// If we have too many lines, remove the oldest line. This way we
|
||||
// never have to hold the full contents of a huge log file in memory.
|
||||
// Adding to and removing from the ends of a linked list are cheap
|
||||
// operations.
|
||||
if (lineCount > maxLines)
|
||||
logLines.remove(0);
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
// If the log has been truncated, include that information.
|
||||
|
||||
Reference in new issue
Block a user