opal/cr: fix misc memory leak and error case
as reported by Coverity with CIDs 71858 and 710640
Этот коммит содержится в:
родитель
2789d782ab
Коммит
1746e23f11
@ -13,6 +13,8 @@
|
|||||||
* reserved.
|
* reserved.
|
||||||
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
|
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
|
||||||
* Copyright (c) 2012-2013 Cisco Systems, Inc. All rights reserved.
|
* Copyright (c) 2012-2013 Cisco Systems, 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
|
||||||
@ -917,7 +919,7 @@ int opal_cr_reg_coord_callback(opal_cr_coord_callback_fn_t new_func,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int opal_cr_refresh_environ(int prev_pid) {
|
int opal_cr_refresh_environ(int prev_pid) {
|
||||||
char *file_name = NULL;
|
char *file_name;
|
||||||
#if OPAL_ENABLE_CRDEBUG == 1
|
#if OPAL_ENABLE_CRDEBUG == 1
|
||||||
char *tmp;
|
char *tmp;
|
||||||
#endif
|
#endif
|
||||||
@ -933,7 +935,11 @@ int opal_cr_refresh_environ(int prev_pid) {
|
|||||||
* 2) The file has been deleted on the previous round.
|
* 2) The file has been deleted on the previous round.
|
||||||
*/
|
*/
|
||||||
asprintf(&file_name, "%s/%s-%d", opal_tmp_directory(), OPAL_CR_BASE_ENV_NAME, prev_pid);
|
asprintf(&file_name, "%s/%s-%d", opal_tmp_directory(), OPAL_CR_BASE_ENV_NAME, prev_pid);
|
||||||
|
if (NULL == file_name) {
|
||||||
|
return OPAL_ERR_OUT_OF_RESOURCE;
|
||||||
|
}
|
||||||
if(0 != stat(file_name, &file_status) ){
|
if(0 != stat(file_name, &file_status) ){
|
||||||
|
free(file_name);
|
||||||
return OPAL_SUCCESS;
|
return OPAL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -958,10 +964,7 @@ int opal_cr_refresh_environ(int prev_pid) {
|
|||||||
(MPIR_debug_with_checkpoint ? "True": "False"));
|
(MPIR_debug_with_checkpoint ? "True": "False"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( NULL != file_name ){
|
free(file_name);
|
||||||
free(file_name);
|
|
||||||
file_name = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OPAL_SUCCESS;
|
return OPAL_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -990,17 +993,16 @@ static int extract_env_vars(int prev_pid, char * file_name)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp_str = (char *) malloc(sizeof(char) * OPAL_PATH_MAX);
|
||||||
|
if( NULL == tmp_str) {
|
||||||
|
exit_status = OPAL_ERR_OUT_OF_RESOURCE;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
/* Extract an env var */
|
/* Extract an env var */
|
||||||
while(!feof(env_data) ) {
|
while(!feof(env_data) ) {
|
||||||
char **t_set = NULL;
|
char **t_set = NULL;
|
||||||
len = OPAL_PATH_MAX;
|
|
||||||
|
|
||||||
tmp_str = (char *) malloc(sizeof(char) * len);
|
if( NULL == fgets(tmp_str, OPAL_PATH_MAX, env_data) ) {
|
||||||
if( NULL == tmp_str) {
|
|
||||||
exit_status = OPAL_ERR_OUT_OF_RESOURCE;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if( NULL == fgets(tmp_str, len, env_data) ) {
|
|
||||||
exit_status = OPAL_ERROR;
|
exit_status = OPAL_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1011,7 +1013,6 @@ static int extract_env_vars(int prev_pid, char * file_name)
|
|||||||
opal_output(opal_cr_output,
|
opal_output(opal_cr_output,
|
||||||
"opal_cr: extract_env_vars: Error: Parameter too long (%s)\n",
|
"opal_cr: extract_env_vars: Error: Parameter too long (%s)\n",
|
||||||
tmp_str);
|
tmp_str);
|
||||||
free(tmp_str);
|
|
||||||
tmp_str = NULL;
|
tmp_str = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1022,8 +1023,7 @@ static int extract_env_vars(int prev_pid, char * file_name)
|
|||||||
|
|
||||||
opal_setenv(t_set[0], t_set[1], true, &environ);
|
opal_setenv(t_set[0], t_set[1], true, &environ);
|
||||||
|
|
||||||
free(tmp_str);
|
opal_argv_free(t_set);
|
||||||
tmp_str = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user