From: Bon-Yong Lee Date: Wed, 27 Nov 2013 03:00:58 +0000 (+0900) Subject: CLI: Fix resource leak X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F12964%2F1;p=sdk%2Ftools%2Fcli.git CLI: Fix resource leak Fix missing #close of resource Change-Id: Id2c0372adc4988be07f0147f218aab7ce9bc9697 Signed-off-by: Bon-Yong Lee --- diff --git a/org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java b/org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java old mode 100644 new mode 100755 index d212c4c..ef2a3ac --- a/org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java +++ b/org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java @@ -24,8 +24,11 @@ */ package org.tizen.cli.exec; +import static org.tizen.sdblib.util.IOUtil.tryClose; + import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; @@ -286,14 +289,22 @@ AbstractLauncher { final URL url = iter.nextElement(); logger.trace( "URL :{}", url ); - final Properties properties = PropertyUtil.loadProperties( url.openStream() ); - logger.debug( "Properties :{}", properties ); - - for ( final Object key : properties.keySet() ) + final InputStream in = url.openStream(); + try + { + final Properties properties = PropertyUtil.loadProperties( in ); + logger.debug( "Properties :{}", properties ); + + for ( final Object key : properties.keySet() ) + { + final String value = properties.getProperty( (String) key ); + byte[] contents = IOUtil.getBytes( cl.getResourceAsStream( value ), true ); + this.help.addHelpDetail( (String) key, new String( contents, Charset.forName( "utf8" ) ) ); + } + } + finally { - final String value = properties.getProperty( (String) key ); - byte[] contents = IOUtil.getBytes( cl.getResourceAsStream( value ), true ); - this.help.addHelpDetail( (String) key, new String( contents, Charset.forName( "utf8" ) ) ); + tryClose( in ); } } }