mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fixing coverity issues related to resource leak on FileInputStream being created anonymously
Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
parent
2774b62d64
commit
d19688103b
@ -58,6 +58,7 @@ import org.apache.axis2.databinding.ADBBean;
|
||||
import org.apache.axis2.databinding.ADBException;
|
||||
import org.apache.axis2.databinding.utils.writer.MTOMAwareXMLSerializer;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
||||
@ -103,7 +104,6 @@ import com.amazon.ec2.RunInstancesResponse;
|
||||
import com.amazon.ec2.StartInstancesResponse;
|
||||
import com.amazon.ec2.StopInstancesResponse;
|
||||
import com.amazon.ec2.TerminateInstancesResponse;
|
||||
|
||||
import com.cloud.bridge.model.UserCredentialsVO;
|
||||
import com.cloud.bridge.persist.dao.CloudStackUserDaoImpl;
|
||||
import com.cloud.bridge.persist.dao.OfferingDaoImpl;
|
||||
@ -203,12 +203,16 @@ public class EC2RestServlet extends HttpServlet {
|
||||
if (null != propertiesFile) {
|
||||
logger.info("Use EC2 properties file: " + propertiesFile.getAbsolutePath());
|
||||
EC2Prop = new Properties();
|
||||
FileInputStream ec2PropFile = null;
|
||||
try {
|
||||
EC2Prop.load(new FileInputStream(propertiesFile));
|
||||
ec2PropFile = new FileInputStream(propertiesFile);
|
||||
EC2Prop.load(ec2PropFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(ec2PropFile);
|
||||
}
|
||||
String keystore = EC2Prop.getProperty("keystore");
|
||||
keystorePassword = EC2Prop.getProperty("keystorePass");
|
||||
|
||||
@ -34,15 +34,14 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.axis2.AxisFault;
|
||||
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.amazon.ec2.AmazonEC2SkeletonInterface;
|
||||
import com.amazon.s3.AmazonS3SkeletonInterface;
|
||||
|
||||
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
|
||||
|
||||
import com.cloud.bridge.model.MHostVO;
|
||||
import com.cloud.bridge.model.SHost;
|
||||
import com.cloud.bridge.model.SHostVO;
|
||||
@ -111,8 +110,8 @@ public class ServiceProvider extends ManagerBase {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
|
||||
initialize();
|
||||
return true;
|
||||
}
|
||||
@ -268,12 +267,16 @@ public class ServiceProvider extends ManagerBase {
|
||||
File propertiesFile = ConfigurationHelper.findConfigurationFile("cloud-bridge.properties");
|
||||
properties = new Properties();
|
||||
if (propertiesFile != null) {
|
||||
FileInputStream startProps = null;
|
||||
try {
|
||||
properties.load(new FileInputStream(propertiesFile));
|
||||
startProps = new FileInputStream(propertiesFile);
|
||||
properties.load(startProps);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(startProps);
|
||||
}
|
||||
|
||||
logger.info("Use startup properties file: " + propertiesFile.getAbsolutePath());
|
||||
|
||||
@ -35,6 +35,7 @@ import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.xml.sax.SAXException;
|
||||
@ -122,12 +123,18 @@ public class EC2Engine extends ManagerBase {
|
||||
if (null != propertiesFile) {
|
||||
logger.info("Use EC2 properties file: " + propertiesFile.getAbsolutePath());
|
||||
Properties EC2Prop = new Properties();
|
||||
FileInputStream ec2PropFile = null;
|
||||
try {
|
||||
EC2Prop.load(new FileInputStream(propertiesFile));
|
||||
ec2PropFile = new FileInputStream( propertiesFile );
|
||||
EC2Prop.load(ec2PropFile);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(ec2PropFile);
|
||||
}
|
||||
managementServer = EC2Prop.getProperty("managementServer");
|
||||
cloudAPIPort = EC2Prop.getProperty("cloudAPIPort", null);
|
||||
@ -1217,7 +1224,7 @@ public class EC2Engine extends ManagerBase {
|
||||
throw new EC2ServiceException(ServerError.InternalError, "No Customize Disk Offering Found");
|
||||
}
|
||||
|
||||
// // -> no volume name is given in the Amazon request but is required in the cloud API
|
||||
// -> no volume name is given in the Amazon request but is required in the cloud API
|
||||
CloudStackVolume vol =
|
||||
getApi().createVolume(UUID.randomUUID().toString(), null, diskOfferingId, null, size, snapshotId, toZoneId(request.getZoneName(), null));
|
||||
if (vol != null) {
|
||||
|
||||
@ -40,13 +40,12 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigDepot;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.Configurable;
|
||||
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.cluster.dao.ManagementServerHostDao;
|
||||
import com.cloud.cluster.dao.ManagementServerHostPeerDao;
|
||||
@ -625,8 +624,10 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C
|
||||
if (_heartbeatConnection != null) {
|
||||
Connection conn = TransactionLegacy.getStandaloneConnection();
|
||||
if (conn != null) {
|
||||
_heartbeatConnection.reset(TransactionLegacy.getStandaloneConnection());
|
||||
_heartbeatConnection.reset(conn);
|
||||
}
|
||||
// The stand-alone connection does not have to be closed here because there will be another reference to it.
|
||||
// As a matter of fact, it will be assigned to the connection instance variable in the ConnectionConcierge class.
|
||||
}
|
||||
}
|
||||
|
||||
@ -734,7 +735,6 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ package com.cloud.consoleproxy;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -35,11 +36,10 @@ import java.util.concurrent.Executor;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
import com.cloud.consoleproxy.util.Logger;
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -387,6 +387,12 @@ public class ConsoleProxy {
|
||||
conf.load(confs);
|
||||
} catch (Exception e) {
|
||||
s_logger.error(e.toString(), e);
|
||||
} finally {
|
||||
try {
|
||||
confs.close();
|
||||
} catch (IOException ioex) {
|
||||
s_logger.error(ioex.toString(), ioex);
|
||||
}
|
||||
}
|
||||
}
|
||||
start(conf);
|
||||
@ -454,6 +460,7 @@ public class ConsoleProxy {
|
||||
throw new AuthenticationException("Cannot use the existing viewer " + viewer + ": bad sid");
|
||||
|
||||
if (!viewer.isFrontEndAlive()) {
|
||||
|
||||
authenticationExternally(param);
|
||||
viewer.initClient(param);
|
||||
reportLoadChange = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user