1
1

mca/base: fix misc memory leaks

as reported by Coverity with CIDs 710628, 1196713 and 1269855
Этот коммит содержится в:
Gilles Gouaillardet 2015-03-03 13:40:29 +09:00
родитель 134c866aa9
Коммит 852dbafd51
2 изменённых файлов: 14 добавлений и 11 удалений

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

@ -12,6 +12,8 @@
* All rights reserved. * All rights reserved.
* Copyright (c) 2008-2010 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2008-2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2008 Sun Microsystems, 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
@ -339,14 +341,13 @@ static void find_dyn_components(const char *path, const char *type_name,
done */ done */
return; return;
} }
} else {
path_to_use = strdup(path);
}
if (NULL == path_to_use) { if (NULL == path_to_use) {
/* out of memory */ /* out of memory */
return; return;
} }
} else {
path_to_use = strdup(path);
}
/* If we haven't done so already, iterate over all the files in /* If we haven't done so already, iterate over all the files in
the directories in the path and make a master array of all the the directories in the path and make a master array of all the
@ -417,6 +418,7 @@ static void find_dyn_components(const char *path, const char *type_name,
found_files list */ found_files list */
file = OBJ_NEW(component_file_item_t); file = OBJ_NEW(component_file_item_t);
if (NULL == file) { if (NULL == file) {
free(path_to_use);
return; return;
} }
strncpy(file->type, type_name, MCA_BASE_MAX_TYPE_NAME_LEN); strncpy(file->type, type_name, MCA_BASE_MAX_TYPE_NAME_LEN);

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

@ -14,6 +14,8 @@
* Copyright (c) 2012-2014 Los Alamos National Security, LLC. All rights * Copyright (c) 2012-2014 Los Alamos National Security, LLC. All rights
* reserved. * 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
@ -1096,13 +1098,12 @@ static int fixup_files(char **file_list, char * path, bool rel_path_search) {
for (i = 0 ; i < count; ++i) { for (i = 0 ; i < count; ++i) {
/* Absolute paths preserved */ /* Absolute paths preserved */
if ( opal_path_is_absolute(files[i]) ) { if ( opal_path_is_absolute(files[i]) ) {
if( NULL == opal_path_access(files[i], NULL, mode) ) { if( NULL == (tmp_file = opal_path_access(files[i], NULL, mode)) ) {
opal_show_help("help-mca-var.txt", "missing-param-file", opal_show_help("help-mca-var.txt", "missing-param-file",
true, getpid(), files[i], path); true, getpid(), files[i], path);
exit_status = OPAL_ERROR; exit_status = OPAL_ERROR;
goto cleanup; goto cleanup;
} } else {
else {
opal_argv_append(&argc, &argv, files[i]); opal_argv_append(&argc, &argv, files[i]);
} }
} }
@ -1138,8 +1139,6 @@ static int fixup_files(char **file_list, char * path, bool rel_path_search) {
else { else {
if( NULL != (tmp_file = opal_path_find(files[i], search_path, mode, NULL)) ) { if( NULL != (tmp_file = opal_path_find(files[i], search_path, mode, NULL)) ) {
opal_argv_append(&argc, &argv, tmp_file); opal_argv_append(&argc, &argv, tmp_file);
free(tmp_file);
tmp_file = NULL;
} }
else { else {
opal_show_help("help-mca-var.txt", "missing-param-file", opal_show_help("help-mca-var.txt", "missing-param-file",
@ -1148,8 +1147,11 @@ static int fixup_files(char **file_list, char * path, bool rel_path_search) {
goto cleanup; goto cleanup;
} }
} }
free(tmp_file);
} }
tmp_file = NULL;
free(*file_list); free(*file_list);
*file_list = opal_argv_join(argv, OPAL_ENV_SEP); *file_list = opal_argv_join(argv, OPAL_ENV_SEP);
@ -1168,7 +1170,6 @@ static int fixup_files(char **file_list, char * path, bool rel_path_search) {
} }
if( NULL != tmp_file ) { if( NULL != tmp_file ) {
free(tmp_file); free(tmp_file);
tmp_file = NULL;
} }
return exit_status; return exit_status;