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; }