Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 63034176AD for ; Fri, 10 Jul 2015 10:08:07 +0000 (UTC) Received: (qmail 53872 invoked by uid 500); 10 Jul 2015 10:07:58 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 53773 invoked by uid 500); 10 Jul 2015 10:07:58 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 52887 invoked by uid 99); 10 Jul 2015 10:07:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Jul 2015 10:07:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D63ECE6861; Fri, 10 Jul 2015 10:07:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: widodh@apache.org To: commits@cloudstack.apache.org Date: Fri, 10 Jul 2015 10:08:30 -0000 Message-Id: <9f7490e20d0845a3a51e349f8d9e1acc@git.apache.org> In-Reply-To: <59f1148a7112472fa67aee6264bb0856@git.apache.org> References: <59f1148a7112472fa67aee6264bb0856@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [35/50] git commit: updated refs/heads/CLOUDSTACK-8581 to 1a2e80b coverity 1296982: standard prepared statement and result set leakage Signed-off-by: Daan Hoogland Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/803d6ed7 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/803d6ed7 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/803d6ed7 Branch: refs/heads/CLOUDSTACK-8581 Commit: 803d6ed7df6ca86298a2da749ef2352ea07d1e75 Parents: 6376503 Author: Daan Hoogland Authored: Tue Jul 7 12:40:47 2015 +0200 Committer: Daan Hoogland Committed: Thu Jul 9 21:30:23 2015 +0200 ---------------------------------------------------------------------- engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/803d6ed7/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java index 14870e7..2c68210 100644 --- a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java +++ b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java @@ -641,30 +641,23 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use TransactionLegacy txn = TransactionLegacy.currentTxn(); List, Pair>> vmsDetailByNames = new ArrayList, Pair>>(); - PreparedStatement pstmt = null; - try { - pstmt = txn.prepareStatement(VMS_DETAIL_BY_NAME + getQueryBatchAppender(vmNames.size())); + try (PreparedStatement pstmt = txn.prepareStatement(VMS_DETAIL_BY_NAME + getQueryBatchAppender(vmNames.size()));) { pstmt.setString(1, detail); int i = 2; for(String name : vmNames) { pstmt.setString(i, name); i++; } - try { - ResultSet rs = pstmt.executeQuery(); + try (ResultSet rs = pstmt.executeQuery();) { while (rs.next()) { vmsDetailByNames.add(new Pair, Pair>(new Pair( rs.getString("vm_instance.instance_name"), VirtualMachine.Type.valueOf(rs.getString("vm_type"))), new Pair(rs.getLong("vm_instance.id"), rs.getString("user_vm_details.value")))); } - rs.close(); } catch (Exception e) { s_logger.error("GetVmsDetailsByNames: Exception: " + e.getMessage()); throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage()); } - if(pstmt != null) { - pstmt.close(); - } } catch (Exception e) { s_logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage()); throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage());