felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r882590 - /felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java
Date Fri, 20 Nov 2009 14:52:22 GMT
Author: gnodet
Date: Fri Nov 20 14:52:20 2009
New Revision: 882590

URL: http://svn.apache.org/viewvc?rev=882590&view=rev
Log:
FELIX-1878: karaf.main.Main possible resource leaks and ignored exceptions from mkdirs()

Modified:
    felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java

Modified: felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java?rev=882590&r1=882589&r2=882590&view=diff
==============================================================================
--- felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java (original)
+++ felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java Fri Nov 20
14:52:20 2009
@@ -184,7 +184,11 @@
 
         if (configProps.getProperty(Constants.FRAMEWORK_STORAGE) == null) {
             File storage = new File(karafBase.getPath(), "data/cache");
-            storage.mkdirs();
+            try {
+                storage.mkdirs();
+            } catch (SecurityException se) {
+                throw new Exception(se.getMessage()); 
+            }
             configProps.setProperty(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());
         }
         
@@ -358,29 +362,40 @@
                 File propertiesFile = new File(storageFile, "instance.properties");
                 Properties props = new Properties();
                 if (propertiesFile.exists()) {
-                    props.load(new FileInputStream(propertiesFile));
+                    FileInputStream fis = new FileInputStream(propertiesFile);
+                    props.load(fis);
                     int count = Integer.parseInt(props.getProperty("count"));
                     for (int i = 0; i < count; i++) {
                         String name = props.getProperty("item." + i + ".name");
                         if (name.equals(instanceName)) {
                             props.setProperty("item." + i + ".pid", pid);
-                            props.store(new FileOutputStream(propertiesFile), null);
+                            FileOutputStream fos = new FileOutputStream(propertiesFile);
+                            props.store(fos, null);
+                            fis.close();
+                            fos.close();
                             return;
                         }
                     }
+                    fis.close();
                     if (!isRoot) {
                         throw new Exception("Instance " + instanceName + " not found");
                     } 
                 } else if (isRoot) {
                     if (!propertiesFile.getParentFile().exists()) {
-                        propertiesFile.getParentFile().mkdirs();
+                        try {
+                            propertiesFile.getParentFile().mkdirs();
+                        } catch (SecurityException se) {
+                            throw new Exception(se.getMessage());
+                        }
                     }
                     props.setProperty("count", "1");
                     props.setProperty("item.0.name", instanceName);
                     props.setProperty("item.0.loc", karafHome.getAbsolutePath());
                     props.setProperty("item.0.pid", pid);
                     props.setProperty("item.0.root", "true");
-                    props.store(new FileOutputStream(propertiesFile), null);
+                    FileOutputStream fos = new FileOutputStream(propertiesFile);
+                    props.store(fos, null);
+                    fos.close();
                 }
             }
         } catch (Exception e) {



Mime
View raw message