From 8464ea0fdb3d6c19bf4d81c7bca869a6d599d105 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 6 Aug 2008 21:39:40 +0000 Subject: [PATCH] fixed a file handle leak git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11312 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Run.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java index 8bbe17d986..1252725f6d 100644 --- a/core/src/main/java/hudson/model/Run.java +++ b/core/src/main/java/hudson/model/Run.java @@ -924,15 +924,19 @@ public abstract class Run ,RunT extends Run logLines = new LinkedList(); 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.