From 8f14ef84758fb26e62478a5abd2daf858bff2d97 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Wed, 19 Nov 2008 12:25:08 +0000 Subject: [PATCH] SOLR-869 -- Fix file descriptor leak in SolrResourceLoader#getLines git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@718941 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../apache/solr/core/SolrResourceLoader.java | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index a1c38f731dd..2f9cb2633a7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -121,6 +121,8 @@ Bug Fixes 9. SOLR-803: CoreAdminRequest.createCore fails because name parameter isn't set (Sean Colombo via ryan) +10. SOLR-869: Fix file descriptor leak in SolrResourceLoader#getLines (Mark Miller, shalin) + Other Changes ---------------------- diff --git a/src/java/org/apache/solr/core/SolrResourceLoader.java b/src/java/org/apache/solr/core/SolrResourceLoader.java index 3af09959536..59ac141cae9 100644 --- a/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -236,17 +236,23 @@ public class SolrResourceLoader implements ResourceLoader public List getLines(String resource, Charset charset) throws IOException{ BufferedReader input = null; - input = new BufferedReader(new InputStreamReader(openResource(resource), - charset)); + ArrayList lines; + try { + input = new BufferedReader(new InputStreamReader(openResource(resource), + charset)); - ArrayList lines = new ArrayList(); - for (String word=null; (word=input.readLine())!=null;) { - // skip comments - if (word.startsWith("#")) continue; - word=word.trim(); - // skip blank lines - if (word.length()==0) continue; - lines.add(word); + lines = new ArrayList(); + for (String word=null; (word=input.readLine())!=null;) { + // skip comments + if (word.startsWith("#")) continue; + word=word.trim(); + // skip blank lines + if (word.length()==0) continue; + lines.add(word); + } + } finally { + if (input != null) + input.close(); } return lines; }