Skip to contentSkip to conversation

fix remaining potential leaks of info arrays and iwuqp

PATCH In review Jarod Wilson 2 participants 3 messages Jul 28, 2016 – Jul 29, 2016 2 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix remaining potential leaks of info arrays and iwuqp

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 <[email protected]>
CC Tatyana Nikolova <[email protected]>
---
 src/i40iw_uverbs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/i40iw_uverbs.c +4 -2
index ec5f77e..e5753e0 100644
@@ -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;
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1469732963-58257-1-git-send-email-jarod-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

Hi Jarod,

Thank you for the patch, just a couple of things. Please send a V2 and we will include it.

src/i40iw_uverbs.c

Quoted 11 lines
src/i40iw_uverbs.c index ec5f77e..e5753e0 renamed from src/i40iw_uverbs.c +0 -0

100644

src/i40iw_uverbs.c +0 -0
@@ -698,6 +698,7 @@ struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd,

struct ibv_qp_init_attr *attr

src/i40iw_uverbs.c +0 -0
 	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__);

src/i40iw_uverbs.c +1 -0
+		free(iwuqp);

[Chien] Not needed, see changes below.

src/i40iw_uverbs.c struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr · line 711

Quoted 9 lines
src/i40iw_uverbs.c +0 -0
 		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

src/i40iw_uverbs.c +1 -0
 	if (!status) {
 		fprintf(stderr, PFX "%s: failed to map QP\n", __func__);
+		free(iwuqp);

[Chien] Not needed, see changes below.

Quoted 7 lines
src/i40iw_uverbs.c +0 -0
 		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:

src/i40iw_uverbs.c struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr · line 737

Quoted 8 lines
src/i40iw_uverbs.c +1 -2
 	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;

[Chien] Need to remove this. We don't want to return when unwinding resources Same issue as the return NULL I missed.

src/i40iw_uverbs.c struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr · line 741

Quoted 4 lines
src/i40iw_uverbs.c +1 -0
+
 err_destroy_lock:
 	if (pthread_spin_destroy(&iwuqp->lock))
 		return NULL;

[Chien] Not sure why I would bother with the if statement here.
Remove the if check and return NULL. Now everything should flow correctly in the error path.

Quoted 2 lines

--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 748B799B6A00724488C603FD7E5E7EB94C9942EB-XfjTATA9Em864kNsxIetb7fspsVTdybXVpNB7YpNyf8@public.gmane.org

#4 lore raw
Quoted 46 lines · Chien Tin

Hi Jarod,

Thank you for the patch, just a couple of things. Please send a V2 and we will include it.

src/i40iw_uverbs.c

Quoted 11 lines
src/i40iw_uverbs.c index ec5f77e..e5753e0 renamed from src/i40iw_uverbs.c +0 -0

100644

src/i40iw_uverbs.c +0 -0
@@ -698,6 +698,7 @@ struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd,

struct ibv_qp_init_attr *attr

src/i40iw_uverbs.c +0 -0
 	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__);

src/i40iw_uverbs.c +1 -0
+		free(iwuqp);

[Chien] Not needed, see changes below.

src/i40iw_uverbs.c struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr · line 711

Quoted 9 lines
src/i40iw_uverbs.c +0 -0
 		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

src/i40iw_uverbs.c +1 -0
 	if (!status) {
 		fprintf(stderr, PFX "%s: failed to map QP\n", __func__);
+		free(iwuqp);

[Chien] Not needed, see changes below.

Quoted 7 lines
src/i40iw_uverbs.c +0 -0
 		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:

src/i40iw_uverbs.c struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr · line 737

Quoted 8 lines
src/i40iw_uverbs.c +1 -2
 	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;

[Chien] Need to remove this. We don't want to return when unwinding resources Same issue as the return NULL I missed.

Quoted 6 lines

src/i40iw_uverbs.c struct ibv_qp *i40iw_ucreate_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr · line 741

Quoted 4 lines
src/i40iw_uverbs.c +1 -0
+
 err_destroy_lock:
 	if (pthread_spin_destroy(&iwuqp->lock))
 		return NULL;

[Chien] Not sure why I would bother with the if statement here.
Remove the if check and return NULL. Now everything should flow correctly in the error path.

Hm. So one issue I still see, is that if you jump to err_destroy_qp, then pthread_spin_destroy(&iwuqp->lock) will have already been called by i40iw_udestroy_qp(), along with free(iwuqp), and I was thinking there could be a null pointer dereference issue.

Signature · 7 lines
Jarod Wilson
[email protected]

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html