cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject [26/50] [abbrv] Fixed coverity and other resource leak issues
Date Tue, 21 Oct 2014 14:57:04 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/efe1e0a5/server/src/com/cloud/api/doc/ApiXmlDocWriter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java
index 54fdfbe..2d2cada 100644
--- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java
+++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java
@@ -492,8 +492,10 @@ public class ApiXmlDocWriter {
     private static void deleteDir(File dir) {
         if (dir.isDirectory()) {
             String[] children = dir.list();
-            for (int i = 0; i < children.length; i++) {
-                deleteDir(new File(dir, children[i]));
+            if (children != null) {
+                for (int i = 0; i < children.length; i++) {
+                    deleteDir(new File(dir, children[i]));
+                }
             }
         }
         dir.delete();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/efe1e0a5/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index 230ef84..55f80e1 100755
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -962,11 +962,14 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
         List<String> files = new ArrayList<String>();
         if (lFilename.equals("*")) {
             File dir = new File(lDir);
-            for (String file : dir.list()) {
-                if (file.startsWith(".")) {
-                    continue;
+            String [] dir_lst = dir.list();
+            if(dir_lst != null) {
+                for (String file : dir_lst) {
+                    if (file.startsWith(".")) {
+                        continue;
+                    }
+                    files.add(file);
                 }
-                files.add(file);
             }
         } else {
             files.add(lFilename);
@@ -1203,33 +1206,41 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
             try {
                 File prvKeyFile = File.createTempFile("prvkey", null);
                 String prvkeyPath = prvKeyFile.getAbsolutePath();
-                BufferedWriter out = new BufferedWriter(new FileWriter(prvKeyFile));
-                out.write(prvKey);
-                out.close();
+                try(BufferedWriter prvt_key_file = new BufferedWriter(new FileWriter(prvKeyFile));)
{
+                    prvt_key_file.write(prvKey);
+                }catch (IOException e) {
+                    s_logger.debug("Failed to config ssl: " + e.toString());
+                }
 
                 File pubCertFile = File.createTempFile("pubcert", null);
                 String pubCertFilePath = pubCertFile.getAbsolutePath();
 
-                out = new BufferedWriter(new FileWriter(pubCertFile));
-                out.write(pubCert);
-                out.close();
+                try(BufferedWriter pub_cert_file = new BufferedWriter(new FileWriter(pubCertFile));)
{
+                    pub_cert_file.write(pubCert);
+                }catch (IOException e) {
+                    s_logger.debug("Failed to config ssl: " + e.toString());
+                }
 
                 String certChainFilePath = null, rootCACertFilePath = null;
                 File certChainFile = null, rootCACertFile = null;
                 if(certChain != null){
                     certChainFile = File.createTempFile("certchain", null);
                     certChainFilePath = certChainFile.getAbsolutePath();
-                    out = new BufferedWriter(new FileWriter(certChainFile));
-                    out.write(certChain);
-                    out.close();
+                    try(BufferedWriter cert_chain_out = new BufferedWriter(new FileWriter(certChainFile));)
{
+                        cert_chain_out.write(certChain);
+                    }catch (IOException e) {
+                        s_logger.debug("Failed to config ssl: " + e.toString());
+                    }
                 }
 
                 if(rootCACert != null){
                     rootCACertFile = File.createTempFile("rootcert", null);
                     rootCACertFilePath = rootCACertFile.getAbsolutePath();
-                    out = new BufferedWriter(new FileWriter(rootCACertFile));
-                    out.write(rootCACert);
-                    out.close();
+                    try(BufferedWriter root_ca_cert_file = new BufferedWriter(new FileWriter(rootCACertFile));)
{
+                        root_ca_cert_file.write(rootCACert);
+                    }catch (IOException e) {
+                        s_logger.debug("Failed to config ssl: " + e.toString());
+                    }
                 }
 
                 configureSSL(prvkeyPath, pubCertFilePath, certChainFilePath, rootCACertFilePath);


Mime
View raw message