mirror of https://github.com/apache/cloudstack.git
Merge pull request #681 from DaanHoogland/coverity-regressions
Coverity regressions per 10 aug 2015Not all are in here, the db upgrade code seems to stay the main pitfall. * pr/681: coverity 1315775: proper getting of networkLabel coverity 1315774: improvement of code to negate false positive Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
commit
ff66175f55
|
|
@ -34,20 +34,15 @@ public abstract class Upgrade30xBase extends LegacyDbUpgrade {
|
|||
protected String getNetworkLabelFromConfig(Connection conn, String name) {
|
||||
String sql = "SELECT value FROM `cloud`.`configuration` where name = ?";
|
||||
String networkLabel = null;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
try (PreparedStatement pstmt = conn.prepareStatement(sql);) {
|
||||
pstmt.setString(1,name);
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
networkLabel = rs.getString(1);
|
||||
try (ResultSet rs = pstmt.executeQuery();) {
|
||||
if (rs.next()) {
|
||||
networkLabel = rs.getString(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to fetch network label from configuration", e);
|
||||
} finally {
|
||||
closeAutoCloseable(rs);
|
||||
closeAutoCloseable(pstmt);
|
||||
}
|
||||
return networkLabel;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,30 +230,26 @@ public class DbUtil {
|
|||
}
|
||||
|
||||
public static boolean releaseGlobalLock(String name) {
|
||||
Connection conn = getConnectionForGlobalLocks(name, false);
|
||||
if (conn == null) {
|
||||
s_logger.error("Unable to acquire DB connection for global lock system");
|
||||
assert (false);
|
||||
return false;
|
||||
}
|
||||
try (Connection conn = getConnectionForGlobalLocks(name, false);) {
|
||||
if (conn == null) {
|
||||
s_logger.error("Unable to acquire DB connection for global lock system");
|
||||
assert (false);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");
|
||||
pstmt.setString(1, name);
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs != null && rs.first())
|
||||
return rs.getInt(1) > 0;
|
||||
s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
|
||||
try (PreparedStatement pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");) {
|
||||
pstmt.setString(1, name);
|
||||
try (ResultSet rs = pstmt.executeQuery();) {
|
||||
if (rs != null && rs.first()) {
|
||||
return rs.getInt(1) > 0;
|
||||
}
|
||||
s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("RELEASE_LOCK() throws exception ", e);
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("RELEASE_LOCK() throws exception ", e);
|
||||
} finally {
|
||||
closeResultSet(rs);
|
||||
closeStatement(pstmt);
|
||||
closeConnection(conn);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue