1
1

Fix memory leak. Define init_data on a stack instead of allocation it each time.

This commit was SVN r16550.
Этот коммит содержится в:
Gleb Natapov 2007-10-23 11:10:52 +00:00
родитель 9e2d5acf8e
Коммит 657e544e02

Просмотреть файл

@ -926,7 +926,7 @@ btl_openib_component_init(int *num_btl_modules,
/* Copy the btl module structs into a contiguous array and fully
initialize them */
for(i = 0; i < mca_btl_openib_component.ib_num_btls; i++){
mca_btl_openib_frag_init_data_t* init_data;
mca_btl_openib_frag_init_data_t init_data;
int qp;
item = opal_list_remove_first(&btl_list);
ib_selected = (mca_btl_base_selected_module_t*)item;
@ -942,7 +942,6 @@ btl_openib_component_init(int *num_btl_modules,
OBJ_CONSTRUCT(&openib_btl->ib_lock, opal_mutex_t);
OBJ_CONSTRUCT(&openib_btl->send_free_control, ompi_free_list_t);
OBJ_CONSTRUCT(&openib_btl->send_user_free, ompi_free_list_t);
OBJ_CONSTRUCT(&openib_btl->recv_user_free, ompi_free_list_t);
@ -956,97 +955,60 @@ btl_openib_component_init(int *num_btl_modules,
/* initialize the memory pool using the hca */
openib_btl->super.btl_mpool = openib_btl->hca->mpool;
length = sizeof(mca_btl_openib_frag_t);
length = sizeof(mca_btl_openib_send_user_frag_t);
init_data = (mca_btl_openib_frag_init_data_t*)
malloc(sizeof(mca_btl_openib_frag_init_data_t));
init_data.length = length;
init_data.type = MCA_BTL_OPENIB_FRAG_SEND_USER;
init_data.order = mca_btl_openib_component.rdma_qp;
init_data.list = &openib_btl->send_user_free;
init_data->length = length;
init_data->type = MCA_BTL_OPENIB_FRAG_SEND_USER;
init_data->order = mca_btl_openib_component.rdma_qp;
init_data->list = &openib_btl->send_user_free;
if(OMPI_SUCCESS != ompi_free_list_init_ex( &openib_btl->send_user_free,
length,
2,
OBJ_CLASS(mca_btl_openib_send_user_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
NULL,
mca_btl_openib_frag_init,
(void*)init_data)) {
if(OMPI_SUCCESS != ompi_free_list_init_ex(&openib_btl->send_user_free,
length, 2, OBJ_CLASS(mca_btl_openib_send_user_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
NULL, mca_btl_openib_frag_init, &init_data)) {
return NULL;
}
init_data = (mca_btl_openib_frag_init_data_t*)
malloc(sizeof(mca_btl_openib_frag_init_data_t));
init_data->length = length;
init_data->type = MCA_BTL_OPENIB_FRAG_RECV_USER;
init_data->order = mca_btl_openib_component.rdma_qp;
init_data->list = &openib_btl->recv_user_free;
length = sizeof(mca_btl_openib_recv_user_frag_t);
init_data.length = length;
init_data.type = MCA_BTL_OPENIB_FRAG_RECV_USER;
init_data.order = mca_btl_openib_component.rdma_qp;
init_data.list = &openib_btl->recv_user_free;
if(OMPI_SUCCESS != ompi_free_list_init_ex(&openib_btl->recv_user_free,
length,
2,
OBJ_CLASS(mca_btl_openib_recv_user_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
NULL,
mca_btl_openib_frag_init,
(void*)init_data)) {
length, 2, OBJ_CLASS(mca_btl_openib_recv_user_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
NULL, mca_btl_openib_frag_init, &init_data)) {
return NULL;
}
orte_pointer_array_init(&openib_btl->eager_rdma_buffers,
mca_btl_openib_component.max_eager_rdma,
mca_btl_openib_component.max_eager_rdma,
0);
openib_btl->eager_rdma_buffers_count = 0;
btls[i] = &openib_btl->super;
openib_btl->eager_rdma_frag_size = OPAL_ALIGN(
sizeof(mca_btl_openib_header_t) +
sizeof(mca_btl_openib_footer_t) +
openib_btl->super.btl_eager_limit,
mca_btl_openib_component.buffer_alignment, size_t);
length = sizeof(mca_btl_openib_send_frag_control_t) +
sizeof(mca_btl_openib_header_t) +
sizeof(mca_btl_openib_footer_t) +
sizeof(mca_btl_openib_eager_rdma_header_t);
init_data = (mca_btl_openib_frag_init_data_t*)
malloc(sizeof(mca_btl_openib_frag_init_data_t));
init_data->length = sizeof(mca_btl_openib_eager_rdma_header_t);
init_data->type = MCA_BTL_OPENIB_FRAG_CONTROL;
init_data->order = mca_btl_openib_component.eager_rdma_qp;
init_data->list = &openib_btl->send_free_control;
init_data.length = sizeof(mca_btl_openib_eager_rdma_header_t);
init_data.type = MCA_BTL_OPENIB_FRAG_CONTROL;
init_data.order = mca_btl_openib_component.eager_rdma_qp;
init_data.list = &openib_btl->send_free_control;
if(OMPI_SUCCESS != ompi_free_list_init_ex(&openib_btl->send_free_control,
length,
mca_btl_openib_component.buffer_alignment,
OBJ_CLASS(mca_btl_openib_send_frag_control_t),
mca_btl_openib_component.ib_free_list_num,
-1,
mca_btl_openib_component.ib_free_list_inc,
openib_btl->super.btl_mpool,
mca_btl_openib_frag_init,
init_data)) {
length, mca_btl_openib_component.buffer_alignment,
OBJ_CLASS(mca_btl_openib_send_frag_control_t),
mca_btl_openib_component.ib_free_list_num, -1,
mca_btl_openib_component.ib_free_list_inc,
openib_btl->super.btl_mpool, mca_btl_openib_frag_init,
&init_data)) {
return NULL;
}
/* setup all the qps */
/* setup all the qps */
for(qp = 0; qp < mca_btl_openib_component.num_qps; qp++) {
OBJ_CONSTRUCT(&openib_btl->qps[qp].send_free, ompi_free_list_t);
OBJ_CONSTRUCT(&openib_btl->qps[qp].recv_free, ompi_free_list_t);
@ -1056,32 +1018,25 @@ btl_openib_component_init(int *num_btl_modules,
mca_btl_openib_component.qp_infos[qp].u.srq_qp.sd_max;
}
/* Initialize pool of send fragments */
length = sizeof(mca_btl_openib_send_frag_t) +
sizeof(mca_btl_openib_header_t) +
sizeof(mca_btl_openib_footer_t) +
mca_btl_openib_component.qp_infos[qp].size;
init_data = (mca_btl_openib_frag_init_data_t*)
malloc(sizeof(mca_btl_openib_frag_init_data_t));
init_data->length = mca_btl_openib_component.qp_infos[qp].size;
init_data->type = MCA_BTL_OPENIB_FRAG_SEND;
init_data->order = qp;
init_data->list = &openib_btl->qps[qp].send_free;
init_data.length = mca_btl_openib_component.qp_infos[qp].size;
init_data.type = MCA_BTL_OPENIB_FRAG_SEND;
init_data.order = qp;
init_data.list = &openib_btl->qps[qp].send_free;
if(OMPI_SUCCESS != ompi_free_list_init_ex(init_data->list,
length,
mca_btl_openib_component.buffer_alignment,
OBJ_CLASS(mca_btl_openib_send_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
openib_btl->super.btl_mpool,
mca_btl_openib_frag_init,
(void*)init_data)) {
if(OMPI_SUCCESS != ompi_free_list_init_ex(init_data.list,
length, mca_btl_openib_component.buffer_alignment,
OBJ_CLASS(mca_btl_openib_send_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
openib_btl->super.btl_mpool, mca_btl_openib_frag_init,
&init_data)) {
return NULL;
}
@ -1090,28 +1045,37 @@ btl_openib_component_init(int *num_btl_modules,
sizeof(mca_btl_openib_footer_t) +
mca_btl_openib_component.qp_infos[qp].size;
init_data = (mca_btl_openib_frag_init_data_t*)
malloc(sizeof(mca_btl_openib_frag_init_data_t));
init_data->length = mca_btl_openib_component.qp_infos[qp].size;
init_data->type = MCA_BTL_OPENIB_FRAG_RECV;
init_data->order = qp;
init_data->list = &openib_btl->qps[qp].recv_free;
init_data.length = mca_btl_openib_component.qp_infos[qp].size;
init_data.type = MCA_BTL_OPENIB_FRAG_RECV;
init_data.order = qp;
init_data.list = &openib_btl->qps[qp].recv_free;
if(OMPI_SUCCESS != ompi_free_list_init_ex(init_data->list,
length,
mca_btl_openib_component.buffer_alignment,
OBJ_CLASS(mca_btl_openib_recv_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
openib_btl->super.btl_mpool,
mca_btl_openib_frag_init,
init_data)) {
if(OMPI_SUCCESS != ompi_free_list_init_ex(init_data.list,
length, mca_btl_openib_component.buffer_alignment,
OBJ_CLASS(mca_btl_openib_recv_frag_t),
mca_btl_openib_component.ib_free_list_num,
mca_btl_openib_component.ib_free_list_max,
mca_btl_openib_component.ib_free_list_inc,
openib_btl->super.btl_mpool, mca_btl_openib_frag_init,
&init_data)) {
return NULL;
}
}
}
orte_pointer_array_init(&openib_btl->eager_rdma_buffers,
mca_btl_openib_component.max_eager_rdma,
mca_btl_openib_component.max_eager_rdma,
0);
openib_btl->eager_rdma_buffers_count = 0;
btls[i] = &openib_btl->super;
openib_btl->eager_rdma_frag_size = OPAL_ALIGN(
sizeof(mca_btl_openib_header_t) +
sizeof(mca_btl_openib_footer_t) +
openib_btl->super.btl_eager_limit,
mca_btl_openib_component.buffer_alignment, size_t);
}
/* Setup connect module */
if (OMPI_SUCCESS != ompi_btl_openib_connect_base_select()) {