1
1

rmaps/lama: fix misc memory leaks

as reported by Coverity with CIDs 719263, 719264, 1196712 and 1269842
Этот коммит содержится в:
Gilles Gouaillardet 2015-03-02 14:24:32 +09:00
родитель 456baeb71b
Коммит c15b919635
2 изменённых файлов: 33 добавлений и 10 удалений

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

@ -1,6 +1,8 @@
/* /*
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved. * Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* *
* $COPYRIGHT$ * $COPYRIGHT$
* *
@ -983,8 +985,6 @@ hwloc_obj_t * rmaps_lama_find_parent(hwloc_topology_t hwloc_topo,
hwloc_obj_type_t hwloc_key; hwloc_obj_type_t hwloc_key;
int depth; int depth;
cur_parent = (hwloc_obj_t*)malloc(sizeof(hwloc_obj_t) * 1);
/* /*
* Convert LAMA key to HWLOC key * Convert LAMA key to HWLOC key
*/ */
@ -1002,6 +1002,11 @@ hwloc_obj_t * rmaps_lama_find_parent(hwloc_topology_t hwloc_topo,
} }
} }
cur_parent = (hwloc_obj_t*)malloc(sizeof(hwloc_obj_t) * 1);
if (NULL == cur_parent) {
return NULL;
}
/* /*
* Accend tree to find mathing parent * Accend tree to find mathing parent
*/ */

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

@ -3,6 +3,8 @@
* *
* Copyright (c) 2012-2013 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2012-2013 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved * Copyright (c) 2014 Intel, Inc. All rights reserved
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -605,7 +607,14 @@ static int orte_rmaps_lama_map_core(orte_job_t *jdata)
* Find the position of the 'machine' * Find the position of the 'machine'
*/ */
pu_idx_ref = (int*)malloc(sizeof(int) * lama_mapping_num_layouts); pu_idx_ref = (int*)malloc(sizeof(int) * lama_mapping_num_layouts);
if (NULL == pu_idx_ref) {
return ORTE_ERROR;
}
last_pu_idx_ref = (int*)malloc(sizeof(int) * lama_mapping_num_layouts); last_pu_idx_ref = (int*)malloc(sizeof(int) * lama_mapping_num_layouts);
if (NULL == last_pu_idx_ref) {
free(pu_idx_ref);
return ORTE_ERROR;
}
for( i = 0; i < lama_mapping_num_layouts; ++i ) { for( i = 0; i < lama_mapping_num_layouts; ++i ) {
pu_idx_ref[i] = 0; pu_idx_ref[i] = 0;
@ -852,22 +861,22 @@ static int orte_rmaps_lama_map_core(orte_job_t *jdata)
OBJ_RELEASE(item); OBJ_RELEASE(item);
} }
OBJ_RELEASE(node_list); OBJ_RELEASE(node_list);
node_list = NULL;
} }
if( NULL != max_tree ) { if( NULL != max_tree ) {
OBJ_RELEASE(max_tree); OBJ_RELEASE(max_tree);
max_tree = NULL;
} }
if( NULL != pu_idx_ref ) { if( NULL != pu_idx_ref ) {
free(pu_idx_ref); free(pu_idx_ref);
pu_idx_ref = NULL; }
if( NULL != last_pu_idx_ref ) {
free(last_pu_idx_ref);
} }
if( NULL != last_level_str ) { if( NULL != last_level_str ) {
free(last_level_str); free(last_level_str);
last_level_str = NULL;
} }
return exit_status; return exit_status;
@ -1060,7 +1069,8 @@ static int rmaps_lama_map_core_iter_level(orte_job_t *jdata,
&proc); &proc);
if( ORTE_SUCCESS != ret ) { if( ORTE_SUCCESS != ret ) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
return ret; exit_status = ret;
goto bailout;
} }
/* /*
@ -1111,7 +1121,8 @@ static int rmaps_lama_map_core_iter_level(orte_job_t *jdata,
if( lama_binding_level == lama_mapping_layout[cur_level] && lama_binding_num_levels > 1) { if( lama_binding_level == lama_mapping_layout[cur_level] && lama_binding_num_levels > 1) {
opal_output(0, "mca:rmaps:lama: ERROR: Cannot bind to multiple machines - SHOULD NEVER HAPPEN: %s", opal_output(0, "mca:rmaps:lama: ERROR: Cannot bind to multiple machines - SHOULD NEVER HAPPEN: %s",
rmaps_lama_cmd_bind); rmaps_lama_cmd_bind);
return ORTE_ERROR; exit_status = ORTE_ERROR;
goto bailout;
#if 0 #if 0
for( j = 0; j < lama_binding_num_levels; ++j ) { for( j = 0; j < lama_binding_num_levels; ++j ) {
cur_mach = get_next_machine(jdata, node_list, (opal_list_item_t*)cur_mach); cur_mach = get_next_machine(jdata, node_list, (opal_list_item_t*)cur_mach);
@ -1166,6 +1177,7 @@ static int rmaps_lama_map_core_iter_level(orte_job_t *jdata,
*iter_passes += 1; *iter_passes += 1;
} }
bailout:
if( NULL != level_str ) { if( NULL != level_str ) {
free(level_str); free(level_str);
level_str = NULL; level_str = NULL;
@ -1353,7 +1365,7 @@ static int check_node_availability(orte_node_t *cur_node,
int exit_status = ORTE_SUCCESS; int exit_status = ORTE_SUCCESS;
int i; int i;
char * level_str = NULL; char * level_str = NULL;
hwloc_obj_t *topo_child = NULL, *topo_parent=NULL; hwloc_obj_t *topo_child = NULL, *topo_parent, *topo_allocated;
opal_output_verbose(5, orte_rmaps_base_framework.framework_output, opal_output_verbose(5, orte_rmaps_base_framework.framework_output,
@ -1370,7 +1382,10 @@ static int check_node_availability(orte_node_t *cur_node,
* by the PU index. * by the PU index.
* JJH TODO: If homogeneous system then this could be simplified. * JJH TODO: If homogeneous system then this could be simplified.
*/ */
topo_parent = (hwloc_obj_t*)malloc(sizeof(hwloc_obj_t) * 1); topo_allocated = topo_parent = (hwloc_obj_t*)malloc(sizeof(hwloc_obj_t) * 1);
if (NULL == topo_parent) {
return ORTE_ERROR;
}
*topo_parent = hwloc_get_obj_by_depth(cur_node->topology, 0, 0); *topo_parent = hwloc_get_obj_by_depth(cur_node->topology, 0, 0);
for( i = 0; i < lama_mapping_num_layouts; ++i ) { for( i = 0; i < lama_mapping_num_layouts; ++i ) {
/* /*
@ -1447,6 +1462,8 @@ static int check_node_availability(orte_node_t *cur_node,
} }
} }
free(topo_allocated);
return exit_status; return exit_status;
} }
@ -1776,6 +1793,7 @@ static char * get_native_slot_list(orte_node_t *cur_node, hwloc_obj_t *pu_obj, i
cleanup: cleanup:
hwloc_bitmap_free(scratch_cpuset); hwloc_bitmap_free(scratch_cpuset);
hwloc_bitmap_free(binding_cpuset); hwloc_bitmap_free(binding_cpuset);
free(binding_parent);
return slot_list; return slot_list;
} }