Skip to content

Commit 5efded3

Browse files
committed
Fixed few coverity issues reported
1 parent fd96ad0 commit 5efded3

2 files changed

Lines changed: 35 additions & 35 deletions

File tree

agent/src/com/cloud/agent/Agent.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,27 @@ protected void cancelTasks() {
297297

298298
public void sendStartup(Link link) {
299299
final StartupCommand[] startup = _resource.initialize();
300-
final Command[] commands = new Command[startup.length];
301-
for (int i = 0; i < startup.length; i++) {
302-
setupStartupCommand(startup[i]);
303-
commands[i] = startup[i];
304-
}
305-
306-
final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false);
307-
request.setSequence(getNextSequence());
300+
if (startup != null) {
301+
final Command[] commands = new Command[startup.length];
302+
for (int i = 0; i < startup.length; i++) {
303+
setupStartupCommand(startup[i]);
304+
commands[i] = startup[i];
305+
}
306+
final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false);
307+
request.setSequence(getNextSequence());
308308

309-
if (s_logger.isDebugEnabled()) {
310-
s_logger.debug("Sending Startup: " + request.toString());
311-
}
312-
synchronized (this) {
313-
_startup = new StartupTask(link);
314-
_timer.schedule(_startup, _startupWait);
315-
}
316-
try {
317-
link.send(request.toBytes());
318-
} catch (final ClosedChannelException e) {
319-
s_logger.warn("Unable to send reques: " + request.toString());
309+
if (s_logger.isDebugEnabled()) {
310+
s_logger.debug("Sending Startup: " + request.toString());
311+
}
312+
synchronized (this) {
313+
_startup = new StartupTask(link);
314+
_timer.schedule(_startup, _startupWait);
315+
}
316+
try {
317+
link.send(request.toBytes());
318+
} catch (final ClosedChannelException e) {
319+
s_logger.warn("Unable to send reques: " + request.toString());
320+
}
320321
}
321322
}
322323

agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,10 @@ private Answer execute(StartConsoleProxyAgentHttpHandlerCommand cmd) {
120120
}
121121

122122
private void disableRpFilter() {
123-
try {
124-
FileWriter fstream = new FileWriter("/proc/sys/net/ipv4/conf/eth2/rp_filter");
125-
BufferedWriter out = new BufferedWriter(fstream);
123+
try (FileWriter fstream = new FileWriter("/proc/sys/net/ipv4/conf/eth2/rp_filter");
124+
BufferedWriter out = new BufferedWriter(fstream);)
125+
{
126126
out.write("0");
127-
out.close();
128127
} catch (IOException e) {
129128
s_logger.warn("Unable to disable rp_filter");
130129
}
@@ -242,18 +241,18 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
242241

243242
if (_localgw != null) {
244243
String mgmtHost = (String)params.get("host");
245-
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
246-
247-
String internalDns1 = (String)params.get("internaldns1");
248-
if (internalDns1 == null) {
249-
s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
250-
} else {
251-
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns1);
252-
}
253-
254-
String internalDns2 = (String)params.get("internaldns2");
255-
if (internalDns2 != null) {
256-
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2);
244+
if (_eth1ip != null) {
245+
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost);
246+
String internalDns1 = (String) params.get("internaldns1");
247+
if (internalDns1 == null) {
248+
s_logger.warn("No DNS entry found during configuration of NfsSecondaryStorage");
249+
} else {
250+
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns1);
251+
}
252+
String internalDns2 = (String) params.get("internaldns2");
253+
if (internalDns2 != null) {
254+
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2);
255+
}
257256
}
258257
}
259258

0 commit comments

Comments
 (0)