[ofa-general] [PATCH] [DAPL v1] fix memory leak in provider specific post send/recv

Patrick Marchand Latifi patrick.latifi at qlogic.com
Tue Feb 19 16:49:45 PST 2008


Fix memory leak in provider specific post send/recv if there's
more than DEFAULT_DS_ENTRIES iovecs.

Signed-off-by: Patrick Marchand Latifi <patrick.latifi at qlogic.com>
---

 dapl/openib/dapl_ib_dto.h     |   30 ++++++++++++++++++++++--------
 dapl/openib_cma/dapl_ib_dto.h |   30 +++++++++++++++++++++---------
 dapl/openib_scm/dapl_ib_dto.h |   30 ++++++++++++++++++++++--------
 3 files changed, 65 insertions(+), 25 deletions(-)

diff --git a/dapl/openib/dapl_ib_dto.h b/dapl/openib/dapl_ib_dto.h
index c42ea8d..8b0e8fe 100644
--- a/dapl/openib/dapl_ib_dto.h
+++ b/dapl/openib/dapl_ib_dto.h
@@ -67,10 +67,11 @@ dapls_ib_post_recv (
 	IN  DAT_LMR_TRIPLET	*local_iov )
 {
 	ib_data_segment_t	ds_array[DEFAULT_DS_ENTRIES];
-	ib_data_segment_t	*ds_array_p;
+	ib_data_segment_t	*ds_array_p, *ds_array_start_p;
 	struct ibv_recv_wr	wr;
 	struct ibv_recv_wr	*bad_wr;
 	DAT_COUNT		i, total_len;
+	int			ret;
 	
 	dapl_dbg_log (DAPL_DBG_TYPE_EP,
 		      " post_rcv: ep %p cookie %p segs %d l_iov %p\n",
@@ -79,7 +80,8 @@ dapls_ib_post_recv (
 	if ( segments <= DEFAULT_DS_ENTRIES ) 
 		ds_array_p = ds_array;
 	else
-		ds_array_p = dapl_os_alloc(segments * sizeof(ib_data_segment_t));
+		ds_array_start_p = ds_array_p =
+			dapl_os_alloc(segments * sizeof(ib_data_segment_t));
 
 	if (NULL == ds_array_p)
 		return (DAT_INSUFFICIENT_RESOURCES);
@@ -112,9 +114,14 @@ dapls_ib_post_recv (
 	if (cookie != NULL) 
 		cookie->val.dto.size = total_len;
 
-	if (ibv_post_recv(ep_ptr->qp_handle, &wr, &bad_wr))
-		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+	ret = ibv_post_recv(ep_ptr->qp_handle, &wr, &bad_wr);
 	
+	if (segments > DEFAULT_DS_ENTRIES)
+		dapl_os_free(ds_array_start_p, segments * sizeof(ib_data_segment_t));
+
+	if (ret)
+		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+
 	return DAT_SUCCESS;
 }
 
@@ -140,11 +147,12 @@ dapls_ib_post_send (
 		      remote_iov, completion_flags);
 
 	ib_data_segment_t	ds_array[DEFAULT_DS_ENTRIES];
-	ib_data_segment_t	*ds_array_p;
+	ib_data_segment_t	*ds_array_p, *ds_array_start_p;
 	struct ibv_send_wr	wr;
 	struct ibv_send_wr	*bad_wr;
 	ib_hca_transport_t	*ibt_ptr = &ep_ptr->header.owner_ia->hca_ptr->ib_trans;
 	DAT_COUNT		i, total_len;
+	int			ret;
 	
 	dapl_dbg_log (DAPL_DBG_TYPE_EP,
 		      " post_snd: ep %p cookie %p segs %d l_iov %p\n",
@@ -153,7 +161,8 @@ dapls_ib_post_send (
 	if( segments <= DEFAULT_DS_ENTRIES ) 
 		ds_array_p = ds_array;
 	else
-		ds_array_p = dapl_os_alloc(segments * sizeof(ib_data_segment_t));
+		ds_array_start_p = ds_array_p =
+			dapl_os_alloc(segments * sizeof(ib_data_segment_t));
 
 	if (NULL == ds_array_p)
 		return (DAT_INSUFFICIENT_RESOURCES);
@@ -213,9 +222,14 @@ dapls_ib_post_send (
 		      " post_snd: op 0x%x flags 0x%x sglist %p, %d\n", 
 			wr.opcode, wr.send_flags, wr.sg_list, wr.num_sge);
 
-	if (ibv_post_send(ep_ptr->qp_handle, &wr, &bad_wr))
-		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+	ret = ibv_post_send(ep_ptr->qp_handle, &wr, &bad_wr);
 	
+	if (segments > DEFAULT_DS_ENTRIES)
+		dapl_os_free(ds_array_start_p, segments * sizeof(ib_data_segment_t));
+
+	if (ret)
+		return( dapl_convert_errno(EFAULT,"ibv_send") );
+
 	dapl_dbg_log (DAPL_DBG_TYPE_EP," post_snd: returned\n");
 	return DAT_SUCCESS;
 }
diff --git a/dapl/openib_cma/dapl_ib_dto.h b/dapl/openib_cma/dapl_ib_dto.h
index c61ef61..4f077de 100644
--- a/dapl/openib_cma/dapl_ib_dto.h
+++ b/dapl/openib_cma/dapl_ib_dto.h
@@ -67,10 +67,11 @@ dapls_ib_post_recv (
 	IN  DAT_LMR_TRIPLET	*local_iov )
 {
 	ib_data_segment_t ds_array[DEFAULT_DS_ENTRIES];
-	ib_data_segment_t *ds_array_p;
+	ib_data_segment_t *ds_array_p, *ds_array_start_p;
 	struct ibv_recv_wr wr;
 	struct ibv_recv_wr *bad_wr;
 	DAT_COUNT i, total_len;
+	int ret;
 	
 	dapl_dbg_log(DAPL_DBG_TYPE_EP,
 		     " post_rcv: ep %p cookie %p segs %d l_iov %p\n",
@@ -79,7 +80,7 @@ dapls_ib_post_recv (
 	if (segments <= DEFAULT_DS_ENTRIES) 
 		ds_array_p = ds_array;
 	else
-		ds_array_p = 
+		ds_array_start_p = ds_array_p = 
 			dapl_os_alloc(segments * sizeof(ib_data_segment_t));
 
 	if (NULL == ds_array_p)
@@ -113,9 +114,14 @@ dapls_ib_post_recv (
 	if (cookie != NULL) 
 		cookie->val.dto.size = total_len;
 
-	if (ibv_post_recv(ep_ptr->qp_handle->cm_id->qp, &wr, &bad_wr))
-		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+	ret = ibv_post_recv(ep_ptr->qp_handle->cm_id->qp, &wr, &bad_wr);
 	
+	if (segments > DEFAULT_DS_ENTRIES)
+	    dapl_os_free(ds_array_start_p, segments * sizeof(ib_data_segment_t));
+
+	if (ret)
+		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+
 	return DAT_SUCCESS;
 }
 
@@ -142,12 +148,13 @@ dapls_ib_post_send (
 		     remote_iov, completion_flags);
 
 	ib_data_segment_t ds_array[DEFAULT_DS_ENTRIES];
-	ib_data_segment_t *ds_array_p;
+	ib_data_segment_t *ds_array_p, *ds_array_start_p;
 	struct ibv_send_wr wr;
 	struct ibv_send_wr *bad_wr;
 	ib_hca_transport_t *ibt_ptr = 
 		&ep_ptr->header.owner_ia->hca_ptr->ib_trans;
 	DAT_COUNT i, total_len;
+	int ret;
 	
 	dapl_dbg_log(DAPL_DBG_TYPE_EP,
 		     " post_snd: ep %p cookie %p segs %d l_iov %p\n",
@@ -156,7 +163,7 @@ dapls_ib_post_send (
 	if(segments <= DEFAULT_DS_ENTRIES) 
 		ds_array_p = ds_array;
 	else
-		ds_array_p = 
+		ds_array_start_p = ds_array_p = 
 			dapl_os_alloc(segments * sizeof(ib_data_segment_t));
 
 	if (NULL == ds_array_p)
@@ -217,9 +224,14 @@ dapls_ib_post_send (
 		     " post_snd: op 0x%x flags 0x%x sglist %p, %d\n", 
 		     wr.opcode, wr.send_flags, wr.sg_list, wr.num_sge);
 
-	if (ibv_post_send(ep_ptr->qp_handle->cm_id->qp, &wr, &bad_wr))
-		return( dapl_convert_errno(EFAULT,"ibv_recv") );
-	
+	ret = ibv_post_send(ep_ptr->qp_handle->cm_id->qp, &wr, &bad_wr);
+
+	if (segments > DEFAULT_DS_ENTRIES)
+	    dapl_os_free(ds_array_start_p, segments * sizeof(ib_data_segment_t));
+
+	if (ret)
+		return( dapl_convert_errno(EFAULT,"ibv_send") );
+
 	dapl_dbg_log(DAPL_DBG_TYPE_EP," post_snd: returned\n");
 	return DAT_SUCCESS;
 }
diff --git a/dapl/openib_scm/dapl_ib_dto.h b/dapl/openib_scm/dapl_ib_dto.h
index c019cc8..cede876 100644
--- a/dapl/openib_scm/dapl_ib_dto.h
+++ b/dapl/openib_scm/dapl_ib_dto.h
@@ -67,10 +67,11 @@ dapls_ib_post_recv (
 	IN  DAT_LMR_TRIPLET	*local_iov )
 {
 	ib_data_segment_t	ds_array[DEFAULT_DS_ENTRIES];
-	ib_data_segment_t	*ds_array_p;
+	ib_data_segment_t	*ds_array_p, *ds_array_start_p;
 	struct ibv_recv_wr	wr;
 	struct ibv_recv_wr	*bad_wr;
 	DAT_COUNT		i, total_len;
+	int			ret;
 	
 	dapl_dbg_log (DAPL_DBG_TYPE_EP,
 		      " post_rcv: ep %p cookie %p segs %d l_iov %p\n",
@@ -79,7 +80,8 @@ dapls_ib_post_recv (
 	if ( segments <= DEFAULT_DS_ENTRIES ) 
 		ds_array_p = ds_array;
 	else
-		ds_array_p = dapl_os_alloc(segments * sizeof(ib_data_segment_t));
+		ds_array_start_p = ds_array_p =
+			dapl_os_alloc(segments * sizeof(ib_data_segment_t));
 
 	if (NULL == ds_array_p)
 		return (DAT_INSUFFICIENT_RESOURCES);
@@ -112,9 +114,14 @@ dapls_ib_post_recv (
 	if (cookie != NULL) 
 		cookie->val.dto.size = total_len;
 
-	if (ibv_post_recv(ep_ptr->qp_handle, &wr, &bad_wr))
-		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+	ret = ibv_post_recv(ep_ptr->qp_handle, &wr, &bad_wr);
 	
+	if (segments > DEFAULT_DS_ENTRIES)
+		dapl_os_free(ds_array_start_p, segments * sizeof(ib_data_segment_t));
+
+	if (ret)
+		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+
 	return DAT_SUCCESS;
 }
 
@@ -140,11 +147,12 @@ dapls_ib_post_send (
 		      remote_iov, completion_flags);
 
 	ib_data_segment_t	ds_array[DEFAULT_DS_ENTRIES];
-	ib_data_segment_t	*ds_array_p;
+	ib_data_segment_t	*ds_array_p, *ds_array_start_p;
 	struct ibv_send_wr	wr;
 	struct ibv_send_wr	*bad_wr;
 	ib_hca_transport_t	*ibt_ptr = &ep_ptr->header.owner_ia->hca_ptr->ib_trans;
 	DAT_COUNT		i, total_len;
+	int			ret;
 	
 	dapl_dbg_log (DAPL_DBG_TYPE_EP,
 		      " post_snd: ep %p cookie %p segs %d l_iov %p\n",
@@ -153,7 +161,8 @@ dapls_ib_post_send (
 	if( segments <= DEFAULT_DS_ENTRIES ) 
 		ds_array_p = ds_array;
 	else
-		ds_array_p = dapl_os_alloc(segments * sizeof(ib_data_segment_t));
+		ds_array_start_p = ds_array_p =
+			dapl_os_alloc(segments * sizeof(ib_data_segment_t));
 
 	if (NULL == ds_array_p)
 		return (DAT_INSUFFICIENT_RESOURCES);
@@ -213,9 +222,14 @@ dapls_ib_post_send (
 		      " post_snd: op 0x%x flags 0x%x sglist %p, %d\n", 
 			wr.opcode, wr.send_flags, wr.sg_list, wr.num_sge);
 
-	if (ibv_post_send(ep_ptr->qp_handle, &wr, &bad_wr))
-		return( dapl_convert_errno(EFAULT,"ibv_recv") );
+	ret = ibv_post_send(ep_ptr->qp_handle, &wr, &bad_wr);
 	
+	if (segments > DEFAULT_DS_ENTRIES)
+		dapl_os_free(ds_array_start_p, segments * sizeof(ib_data_segment_t));
+
+	if (ret)
+		return( dapl_convert_errno(EFAULT,"ibv_send") );
+
 	dapl_dbg_log (DAPL_DBG_TYPE_EP," post_snd: returned\n");
 	return DAT_SUCCESS;
 }




More information about the general mailing list