CLI: Fix resource leak 64/12964/1
authorBon-Yong Lee <bonyong.lee@samsung.com>
Wed, 27 Nov 2013 03:00:58 +0000 (12:00 +0900)
committerBon-Yong Lee <bonyong.lee@samsung.com>
Wed, 27 Nov 2013 03:02:23 +0000 (12:02 +0900)
Fix missing #close of resource

Change-Id: Id2c0372adc4988be07f0147f218aab7ce9bc9697
Signed-off-by: Bon-Yong Lee <bonyong.lee@samsung.com>
org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index d212c4c..ef2a3ac
  */
 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 );
                                        }
                                }
                        }