SOLR-3187: SystemInfoHandler leaks filehandles

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1297423 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sami Siren 2012-03-06 11:08:14 +00:00
parent d7ab78593b
commit 4ebf04948b
2 changed files with 13 additions and 7 deletions

View File

@ -543,6 +543,8 @@ Optimizations
Bug 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 HTMLStripCharFilter

View File

@ -142,11 +142,12 @@ public class SystemInfoHandler extends RequestHandlerBase
if( !os.getName().toLowerCase(Locale.ENGLISH).startsWith( "windows" ) ) {
// Try some command line things
info.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 RequestHandlerBase
private 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() );
}
}
}