linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libi40iw] fix remaining potential leaks of info arrays and iwuqp
@ 2016-07-28 19:09 Jarod Wilson
       [not found] ` <1469732963-58257-1-git-send-email-jarod-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Jarod Wilson @ 2016-07-28 19:09 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA
  Cc: Jarod Wilson, Chien Tin Tung, Tatyana Nikolova

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 <chien.tin.tung-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
CC: Tatyana Nikolova <tatyana.e.nikolova-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Jarod Wilson <jarod-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 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;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-29  3:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-28 19:09 [PATCH libi40iw] fix remaining potential leaks of info arrays and iwuqp Jarod Wilson
     [not found] ` <1469732963-58257-1-git-send-email-jarod-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-28 21:10   ` Tung, Chien Tin
     [not found]     ` <748B799B6A00724488C603FD7E5E7EB94C9942EB-XfjTATA9Em864kNsxIetb7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2016-07-29  3:24       ` Jarod Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).