AMQ-7403: Potential PreparedStatement/ResultSet leak in LeaseDatabaseLocker#determineTimeDifference

This commit is contained in:
Pascal Schumacher 2020-02-11 21:11:25 +01:00
parent 6417d62f60
commit 26a0f8214c
1 changed files with 12 additions and 11 deletions

View File

@ -133,19 +133,20 @@ public class LeaseDatabaseLocker extends AbstractJDBCLocker {
} }
protected long determineTimeDifference(Connection connection) throws SQLException { protected long determineTimeDifference(Connection connection) throws SQLException {
PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime()); try (PreparedStatement statement = connection.prepareStatement(getStatements().getCurrentDateTime());
ResultSet resultSet = statement.executeQuery(); ResultSet resultSet = statement.executeQuery()) {
long result = 0l; long result = 0l;
if (resultSet.next()) { if (resultSet.next()) {
Timestamp timestamp = resultSet.getTimestamp(1); Timestamp timestamp = resultSet.getTimestamp(1);
long diff = System.currentTimeMillis() - timestamp.getTime(); long diff = System.currentTimeMillis() - timestamp.getTime();
if (Math.abs(diff) > maxAllowableDiffFromDBTime) { if (Math.abs(diff) > maxAllowableDiffFromDBTime) {
// off by more than maxAllowableDiffFromDBTime so lets adjust // off by more than maxAllowableDiffFromDBTime so lets adjust
result = (-diff); result = (-diff);
}
LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp);
} }
LOG.info(getLeaseHolderId() + " diff adjust from db: " + result + ", db time: " + timestamp); return result;
} }
return result;
} }
public void doStop(ServiceStopper stopper) throws Exception { public void doStop(ServiceStopper stopper) throws Exception {