From 226b193488638dfeff7a003b8c1ca6c760e00cd1 Mon Sep 17 00:00:00 2001 From: wilderrodrigues Date: Tue, 19 Nov 2013 10:41:04 +0100 Subject: [PATCH] Fix for Coverity issues CID_1116744, CID_1116718 and CID_1116682, all related to resource leak Signed-off-by: Daan Hoogland --- .../serializer/OnwireClassRegistry.java | 8 ++++++-- .../com/cloud/api/doc/ApiXmlDocWriter.java | 19 +++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/framework/ipc/src/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java b/framework/ipc/src/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java index 177ae09a592..83c8a4291e8 100644 --- a/framework/ipc/src/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java +++ b/framework/ipc/src/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java @@ -32,6 +32,8 @@ import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; +import org.apache.commons.io.IOUtils; + // // Finding classes in a given package code is taken and modified from // Credit: http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html @@ -39,7 +41,7 @@ import java.util.jar.JarInputStream; public class OnwireClassRegistry { private List packages = new ArrayList(); - private Map> registry = new HashMap>(); + private final Map> registry = new HashMap>(); public OnwireClassRegistry() { registry.put("Object", Object.class); @@ -166,13 +168,15 @@ public class OnwireClassRegistry { } } } + IOUtils.closeQuietly(jarFile); } } while (jarEntry != null); + IOUtils.closeQuietly(jarFile); return classes; } static String stripFilenameExtension(String file) { return file.substring(0, file.lastIndexOf('.')); } -} +} \ No newline at end of file diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index a91530b3825..d3a8ade7176 100644 --- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java +++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java @@ -41,11 +41,6 @@ import java.util.TreeMap; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import org.apache.log4j.Logger; - -import com.google.gson.annotations.SerializedName; -import com.thoughtworks.xstream.XStream; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCreateCmd; @@ -61,11 +56,14 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.log4j.Logger; import com.cloud.alert.AlertManager; import com.cloud.serializer.Param; import com.cloud.utils.IteratorUtil; import com.cloud.utils.ReflectUtil; +import com.google.gson.annotations.SerializedName; +import com.thoughtworks.xstream.XStream; public class ApiXmlDocWriter { public static final Logger s_logger = Logger.getLogger(ApiXmlDocWriter.class.getName()); @@ -136,6 +134,7 @@ public class ApiXmlDocWriter { try { FileInputStream in = new FileInputStream(fileName); preProcessedCommands.load(in); + in.close(); } catch (FileNotFoundException ex) { System.out.println("Can't find file " + fileName); System.exit(2); @@ -395,13 +394,13 @@ public class ApiXmlDocWriter { // Generate request request.add(new Argument("username", "Username", true)); request.add(new Argument( - "password", - "Hashed password (Default is MD5). If you wish to use any other hashing algorithm, you would need to write a custom authentication adapter See Docs section.", - true)); + "password", + "Hashed password (Default is MD5). If you wish to use any other hashing algorithm, you would need to write a custom authentication adapter See Docs section.", + true)); request.add(new Argument("domain", - "path of the domain that the user belongs to. Example: domain=/com/cloud/internal. If no domain is passed in, the ROOT domain is assumed.", false)); + "path of the domain that the user belongs to. Example: domain=/com/cloud/internal. If no domain is passed in, the ROOT domain is assumed.", false)); request.add(new Argument("domainId", - "id of the domain that the user belongs to. If both domain and domainId are passed in, \"domainId\" parameter takes precendence", false)); + "id of the domain that the user belongs to. If both domain and domainId are passed in, \"domainId\" parameter takes precendence", false)); apiCommand.setRequest(request); // Generate response