1
1
Complements r30073: tighten up the string parsing of the vendor parts
ID MCA param a bit.  Also fix a small memory leak: ensure to free the
array uint32_t's parsed out of the MCA param.

This commit was SVN r30128.

The following SVN revision numbers were found above:
  r30073 --> open-mpi/ompi@6003702a51

The following Trac tickets were found above:
  Ticket 4301 --> https://svn.open-mpi.org/trac/ompi/ticket/4301
Этот коммит содержится в:
Jeff Squyres 2014-01-06 22:16:04 +00:00
родитель e627c91227
Коммит 8bf4ad9030

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

@ -207,6 +207,10 @@ static int usnic_component_close(void)
free(mca_btl_usnic_component.usnic_all_modules); free(mca_btl_usnic_component.usnic_all_modules);
free(mca_btl_usnic_component.usnic_active_modules); free(mca_btl_usnic_component.usnic_active_modules);
if (NULL != mca_btl_usnic_component.vendor_part_ids) {
free(mca_btl_usnic_component.vendor_part_ids);
mca_btl_usnic_component.vendor_part_ids = NULL;
}
return OMPI_SUCCESS; return OMPI_SUCCESS;
} }
@ -299,42 +303,39 @@ static int check_reg_mem_basics(void)
/* /*
* Parse the value returned in the btl_usnic_vendor_part_ids MCA param * Parse the value returned in the btl_usnic_vendor_part_ids MCA param
*/ */
static int parse_vendor_part_ids(void) static int parse_vendor_part_ids(const char *str, uint32_t **part_ids)
{ {
int i, ret = OMPI_SUCCESS; int i, ret = OMPI_SUCCESS;
char *str = mca_btl_usnic_component.vendor_part_ids_string;
char **parts = NULL; char **parts = NULL;
uint32_t *ids;
long id;
*part_ids = NULL;
/* Defensive programming; this should never actually happen */ /* Defensive programming; this should never actually happen */
if (NULL == mca_btl_usnic_component.vendor_part_ids_string) { if (NULL == str) {
ret = OMPI_ERR_BAD_PARAM; ret = OMPI_ERR_BAD_PARAM;
mca_btl_usnic_component.vendor_part_ids_string = strdup("<empty>"); str = "<empty>";
goto out; goto out;
} }
/* Make sure the string starts with (optional whitespace and) a /* Split into a comma-delimited list */
number: stop at the first non-whitespace and see if it's a parts = opal_argv_split(str, ',');
digit. */ ids = calloc(sizeof(uint32_t), opal_argv_count(parts) + 1);
for (i = 0; !isspace(str[i]) && '\0' != str[i]; ++i) { if (NULL == ids) {
continue;
}
if ('\0' != str[i] && !isdigit(str[i])) {
ret = OMPI_ERR_BAD_PARAM;
goto out;
}
/* Ok, we have at least one number */
parts =
opal_argv_split(mca_btl_usnic_component.vendor_part_ids_string, ',');
mca_btl_usnic_component.vendor_part_ids =
calloc(sizeof(uint32_t), opal_argv_count(parts) + 1);
if (NULL == mca_btl_usnic_component.vendor_part_ids) {
ret = OMPI_ERR_OUT_OF_RESOURCE; ret = OMPI_ERR_OUT_OF_RESOURCE;
goto out; goto out;
} }
for (i = 0, str = parts[0]; NULL != str; str = parts[++i]) { for (i = 0, str = parts[0]; NULL != str; str = parts[++i]) {
mca_btl_usnic_component.vendor_part_ids[i] = (uint32_t) atoi(str); id = strtol(str, NULL, 0);
if (id > UINT32_MAX || id <= 0 ||
ERANGE == errno || EINVAL == errno) {
ret = OMPI_ERR_BAD_PARAM;
goto out;
}
ids[i] = (uint32_t) id;
} }
*part_ids = ids;
out: out:
if (NULL != parts) { if (NULL != parts) {
@ -345,15 +346,9 @@ static int parse_vendor_part_ids(void)
if (OMPI_ERR_BAD_PARAM == ret) { if (OMPI_ERR_BAD_PARAM == ret) {
opal_show_help("help-mpi-btl-usnic.txt", opal_show_help("help-mpi-btl-usnic.txt",
"bad value for btl_usnic_vendor_part_ids", "bad value for btl_usnic_vendor_part_ids",
true, true, str);
mca_btl_usnic_component.vendor_part_ids_string);
} }
/* Free the value that we got back from the MCA param (the MCA var
system maintains its own interncal copy) */
free(mca_btl_usnic_component.vendor_part_ids_string);
mca_btl_usnic_component.vendor_part_ids_string = NULL;
return ret; return ret;
} }
@ -501,10 +496,17 @@ static mca_btl_base_module_t** usnic_component_init(int* num_btl_modules,
/* Parse the vendor part IDs returned in /* Parse the vendor part IDs returned in
btl_usnic_vendor_part_ids */ btl_usnic_vendor_part_ids */
if (OMPI_SUCCESS != parse_vendor_part_ids()) { if (OMPI_SUCCESS !=
parse_vendor_part_ids(mca_btl_usnic_component.vendor_part_ids_string,
&mca_btl_usnic_component.vendor_part_ids)) {
return NULL; return NULL;
} }
/* Free the value that we got back from the MCA param (the MCA var
system maintains its own interncal copy) */
free(mca_btl_usnic_component.vendor_part_ids_string);
mca_btl_usnic_component.vendor_part_ids_string = NULL;
/************************************************************************ /************************************************************************
* Below this line, we assume that usnic is loaded on all procs, * Below this line, we assume that usnic is loaded on all procs,
* and therefore we will guarantee to the the modex send, even if * and therefore we will guarantee to the the modex send, even if