Apache Solr open-source search software
SOLR-3187: SystemInfoHandler leaks filehandles
Sami Siren4ebf04948b41
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a3f60bd75a0..e527db35250 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -543,6 +543,8 @@ OptimizationsBug Fixes----------------------+* SOLR-3187 SystemInfoHandler leaks filehandles (siren)+* SOLR-2912: Fixed File descriptor leak in ShowFileRequestHandler (Michael Ryan, shalin)* SOLR-2819: Improved speed of parsing hex entities in HTMLStripCharFilterdiff --git a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.javaindex 93129e24c8e..a06aee12e8e 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java@@ -142,11 +142,12 @@ public class SystemInfoHandler extends RequestHandlerBaseif( !os.getName().toLowerCase(Locale.ENGLISH).startsWith( "windows" ) ) {// Try some command line thingsinfo.add( "uname", execute( "uname -a" ) );- info.add( "ulimit", execute( "ulimit -n" ) );info.add( "uptime", execute( "uptime" ) );}}- catch( Throwable ex ) {} // ignore+ catch( Throwable ex ) {+ ex.printStackTrace();+ }return info;}@@ -181,21 +182,24 @@ public class SystemInfoHandler extends RequestHandlerBaseprivate static String execute( String cmd ){DataInputStream in = null;- BufferedReader reader = null;+ Process process = null;try {- Process process = Runtime.getRuntime().exec(cmd);+ process = Runtime.getRuntime().exec(cmd);in = new DataInputStream( process.getInputStream() );// use default charset from locale here, because the command invoked also uses the default locale:- return IOUtils.toString( in );+ return IOUtils.toString(in);}catch( Exception ex ) {// ignore - log.warn("Error executing command", ex);return "(error executing: " + cmd + ")";}finally {- IOUtils.closeQuietly( reader );- IOUtils.closeQuietly( in );+ if (process != null) {+ IOUtils.closeQuietly( process.getOutputStream() );+ IOUtils.closeQuietly( process.getInputStream() );+ IOUtils.closeQuietly( process.getErrorStream() );+ }}}