1
1
CID 1196720 Resource leak (RESOURCE_LEAK)
CID 1196721 Resource leak (RESOURCE_LEAK)

The code in question does leak loc_token and loc_value. Cleaned up the
code a bit and plugged the leak.

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
Этот коммит содержится в:
Nathan Hjelm 2015-05-27 13:46:38 -06:00
родитель 0e3c32a98a
Коммит 9353fcea95

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

@ -115,19 +115,11 @@ OBJ_CLASS_INSTANCE(opal_crs_base_ckpt_options_t,
* Utility functions * Utility functions
*/ */
int opal_crs_base_metadata_read_token(FILE *metadata, char * token, char ***value) { int opal_crs_base_metadata_read_token(FILE *metadata, char * token, char ***value) {
int exit_status = OPAL_SUCCESS;
char * loc_token = NULL;
char * loc_value = NULL;
int argc = 0; int argc = 0;
/* Dummy check */ /* Dummy check */
if( NULL == token ) { if (NULL == token || NULL == metadata) {
exit_status = OPAL_ERROR; return OPAL_ERROR;
goto cleanup;
}
if( NULL == metadata ) {
exit_status = OPAL_ERROR;
goto cleanup;
} }
/* /*
@ -135,6 +127,8 @@ int opal_crs_base_metadata_read_token(FILE *metadata, char * token, char ***valu
*/ */
rewind(metadata); rewind(metadata);
do { do {
char *loc_token = NULL, *loc_value = NULL;
/* Get next token */ /* Get next token */
if( OPAL_SUCCESS != metadata_extract_next_token(metadata, &loc_token, &loc_value) ) { if( OPAL_SUCCESS != metadata_extract_next_token(metadata, &loc_token, &loc_value) ) {
break; break;
@ -144,13 +138,12 @@ int opal_crs_base_metadata_read_token(FILE *metadata, char * token, char ***valu
if(0 == strncmp(token, loc_token, strlen(loc_token)) ) { if(0 == strncmp(token, loc_token, strlen(loc_token)) ) {
opal_argv_append(&argc, value, loc_value); opal_argv_append(&argc, value, loc_value);
} }
} while(0 == feof(metadata) );
free (loc_token);
cleanup: free (loc_value);
if (NULL != metadata) { } while (0 == feof(metadata));
rewind(metadata);
} return OPAL_SUCCESS;
return exit_status;
} }
int opal_crs_base_extract_expected_component(FILE *metadata, char ** component_name, int *prev_pid) int opal_crs_base_extract_expected_component(FILE *metadata, char ** component_name, int *prev_pid)