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

Patrick Marchand Latifi patrick.latifi at qlogic.com
Tue Feb 19 16:54: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 |   44 +++++++++++++++++++++++++++++------------
 dapl/openib_scm/dapl_ib_dto.h |   30 +++++++++++++++++++++-------
 3 files changed, 75 insertions(+), 29 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 cea989b..b614740 100644
--- a/dapl/openib_cma/dapl_ib_dto.h
+++ b/dapl/openib_cma/dapl_ib_dto.h
@@ -71,10 +71,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",
@@ -83,7 +84,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)
@@ -117,9 +118,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;
 }
 
@@ -145,12 +151,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",
@@ -159,7 +166,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)
@@ -221,9 +228,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;
 }
@@ -291,10 +303,11 @@ dapls_ib_post_ext_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;
 	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",
@@ -303,7 +316,7 @@ dapls_ib_post_ext_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)
@@ -392,8 +405,13 @@ dapls_ib_post_ext_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