btl/tcp: fix CID 1416634
Fix resource leak in the TCP BTL. Also add a little defensive programming. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Этот коммит содержится в:
родитель
8e925b4f17
Коммит
a17f4afdc7
@ -16,7 +16,7 @@
|
||||
* and Technology (RIST). All rights reserved.
|
||||
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* Copyright (c) 2015-2017 Cisco Systems, Inc. All rights reserved
|
||||
* Copyright (c) 2015-2018 Cisco Systems, Inc. All rights reserved
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -417,7 +417,7 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
|
||||
unsigned int perm_size;
|
||||
int rc, *a = NULL;
|
||||
size_t i, j;
|
||||
mca_btl_tcp_interface_t** peer_interfaces;
|
||||
mca_btl_tcp_interface_t** peer_interfaces = NULL;
|
||||
mca_btl_tcp_proc_data_t _proc_data, *proc_data=&_proc_data;
|
||||
size_t max_peer_interfaces;
|
||||
memset(proc_data, 0, sizeof(mca_btl_tcp_proc_data_t));
|
||||
@ -451,7 +451,11 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
|
||||
|
||||
max_peer_interfaces = proc_data->max_local_interfaces;
|
||||
peer_interfaces = (mca_btl_tcp_interface_t**)calloc( max_peer_interfaces, sizeof(mca_btl_tcp_interface_t*) );
|
||||
assert(NULL != peer_interfaces);
|
||||
if (NULL == peer_interfaces) {
|
||||
max_peer_interfaces = 0;
|
||||
rc = OPAL_ERR_OUT_OF_RESOURCE;
|
||||
goto exit;
|
||||
}
|
||||
proc_data->num_peer_interfaces = 0;
|
||||
memset(proc_data->peer_kindex_to_index, -1, sizeof(int)*MAX_KERNEL_INTERFACE_INDEX);
|
||||
|
||||
@ -477,8 +481,9 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
|
||||
max_peer_interfaces <<= 1;
|
||||
peer_interfaces = (mca_btl_tcp_interface_t**)realloc( peer_interfaces,
|
||||
max_peer_interfaces * sizeof(mca_btl_tcp_interface_t*) );
|
||||
if( NULL == peer_interfaces )
|
||||
if( NULL == peer_interfaces ) {
|
||||
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||
}
|
||||
}
|
||||
peer_interfaces[index] = (mca_btl_tcp_interface_t *) malloc(sizeof(mca_btl_tcp_interface_t));
|
||||
mca_btl_tcp_initialise_interface(peer_interfaces[index],
|
||||
@ -633,7 +638,8 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
|
||||
|
||||
a = (int *) malloc(perm_size * sizeof(int));
|
||||
if (NULL == a) {
|
||||
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||
rc = OPAL_ERR_OUT_OF_RESOURCE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Can only find the best set of connections when the number of
|
||||
@ -695,6 +701,9 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
|
||||
OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name));
|
||||
}
|
||||
|
||||
exit:
|
||||
// Ok to always free because proc_data() was memset() to 0 before
|
||||
// any possible return (and free(NULL) is fine).
|
||||
for(i = 0; i < perm_size; ++i) {
|
||||
free(proc_data->weights[i]);
|
||||
free(proc_data->best_addr[i]);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user