From patchwork Thu Jul 28 19:09:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarod Wilson X-Patchwork-Id: 9251569 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2CAD46075F for ; Thu, 28 Jul 2016 19:09:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B59B24B48 for ; Thu, 28 Jul 2016 19:09:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 100EB27D9B; Thu, 28 Jul 2016 19:09:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87B3024B48 for ; Thu, 28 Jul 2016 19:09:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756713AbcG1TJ1 (ORCPT ); Thu, 28 Jul 2016 15:09:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34144 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756531AbcG1TJ1 (ORCPT ); Thu, 28 Jul 2016 15:09:27 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76AFC883A8; Thu, 28 Jul 2016 19:09:26 +0000 (UTC) Received: from hp-dl360pgen8-07.khw.lab.eng.bos.redhat.com (hp-dl360pgen8-07.khw.lab.eng.bos.redhat.com [10.16.184.47]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6SJ9PtE010341; Thu, 28 Jul 2016 15:09:25 -0400 From: Jarod Wilson To: linux-rdma@vger.kernel.org Cc: Jarod Wilson , Chien Tin Tung , Tatyana Nikolova Subject: [PATCH libi40iw] fix remaining potential leaks of info arrays and iwuqp Date: Thu, 28 Jul 2016 15:09:23 -0400 Message-Id: <1469732963-58257-1-git-send-email-jarod@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 28 Jul 2016 19:09:26 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we get to err_destroy_qp, we still need to free info.rq_wrid_array and info.sq_wrtrk_array, so just slide the return down after those respective free() calls, and free iwuqp before gotos below err_destroy_qp, so we do call free() iwuqp, but only once (i40iw_udestroy_qp() also free()'s it). Fixes: 5f13b882d (libi40iw: Add return code check for pthread_spin calls) CC: Chien Tin Tung CC: Tatyana Nikolova Signed-off-by: Jarod Wilson --- src/i40iw_uverbs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/i40iw_uverbs.c b/src/i40iw_uverbs.c index ec5f77e..e5753e0 100644 --- a/src/i40iw_uverbs.c +++ b/src/i40iw_uverbs.c @@ -698,6 +698,7 @@ struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr info.rq_wrid_array = calloc(rqdepth, sizeof(*info.rq_wrid_array)); if (!info.rq_wrid_array) { fprintf(stderr, PFX "%s: failed to allocate memory for RQ work array\n", __func__); + free(iwuqp); goto err_free_sq_wrtrk; } @@ -707,6 +708,7 @@ struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr if (!status) { fprintf(stderr, PFX "%s: failed to map QP\n", __func__); + free(iwuqp); goto err_free_rq_wrid; } info.qp_id = resp.qp_id; @@ -728,12 +730,12 @@ struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr err_destroy_qp: i40iw_udestroy_qp(&iwuqp->ibv_qp); - return NULL; - err_free_rq_wrid: free(info.rq_wrid_array); err_free_sq_wrtrk: free(info.sq_wrtrk_array); + return NULL; + err_destroy_lock: if (pthread_spin_destroy(&iwuqp->lock)) return NULL;