diff --git a/src/slurmctld/node_mgr.c b/src/slurmctld/node_mgr.c index 89429484a3fd2aeb7a08242215c6043054a255e3..e884b82d803204941a4c577d7056d36d5d15219a 100644 --- a/src/slurmctld/node_mgr.c +++ b/src/slurmctld/node_mgr.c @@ -215,14 +215,10 @@ struct config_record * create_config_record (void) config_ptr->nodes = NULL; config_ptr->node_bitmap = NULL; xassert (config_ptr->magic = CONFIG_MAGIC); /* set value */ - if (default_config_record.feature) { - config_ptr->feature = - (char *) - xmalloc (strlen (default_config_record.feature) + 1); - strcpy (config_ptr->feature, default_config_record.feature); - } + if (default_config_record.feature) + config_ptr->feature = xstrdup(default_config_record.feature); else - config_ptr->feature = (char *) NULL; + config_ptr->feature = NULL; if (list_append(config_list, config_ptr) == NULL) fatal ("create_config_record: unable to allocate memory"); diff --git a/src/slurmctld/node_scheduler.c b/src/slurmctld/node_scheduler.c index 7d3aa877d1c61f3790a5f5ff34fe8e4ec6eb9188..af476653f04ff4b369e8b49fa2fb8c7bc63ca8c7 100644 --- a/src/slurmctld/node_scheduler.c +++ b/src/slurmctld/node_scheduler.c @@ -42,6 +42,7 @@ #include "src/common/hostlist.h" #include "src/common/xassert.h" #include "src/common/xmalloc.h" +#include "src/common/xstring.h" #include "src/slurmctld/agent.h" #include "src/slurmctld/slurmctld.h" @@ -232,9 +233,7 @@ static int _match_feature(char *seek, char *available) if (available == NULL) return SLURM_SUCCESS; /* nothing to find */ - tmp_available = xmalloc(strlen(available) + 1); - strcpy(tmp_available, available); - + tmp_available = xstrdup(available); found = 0; str_ptr3 = (char *) strtok_r(tmp_available, ",", &str_ptr4); while (str_ptr3) { @@ -1066,9 +1065,7 @@ static int _valid_features(char *requested, char *available) if (available == NULL) return 0; /* no features */ - tmp_requested = xmalloc(strlen(requested) + 1); - strcpy(tmp_requested, requested); - + tmp_requested = xstrdup(requested); bracket = option = position = 0; str_ptr1 = tmp_requested; /* start of feature name */ result = last_op = 1; /* assume good for now */ diff --git a/src/slurmctld/partition_mgr.c b/src/slurmctld/partition_mgr.c index 7bc45fc8ad28cca67ac12c932122d03c8d9152c3..27e04608ad2dd75850704fca2ab5b5be75d53ff4 100644 --- a/src/slurmctld/partition_mgr.c +++ b/src/slurmctld/partition_mgr.c @@ -189,19 +189,14 @@ struct part_record *create_part_record(void) part_ptr->node_bitmap = NULL; xassert (part_ptr->magic = PART_MAGIC); /* set value */ - if (default_part.allow_groups) { - part_ptr->allow_groups = - (char *) xmalloc(strlen(default_part.allow_groups) + 1); - strcpy(part_ptr->allow_groups, - default_part.allow_groups); - } else + if (default_part.allow_groups) + part_ptr->allow_groups = xstrdup(default_part.allow_groups); + else part_ptr->allow_groups = NULL; - if (default_part.nodes) { - part_ptr->nodes = - (char *) xmalloc(strlen(default_part.nodes) + 1); - strcpy(part_ptr->nodes, default_part.nodes); - } else + if (default_part.nodes) + part_ptr->nodes = xstrdup(default_part.nodes); + else part_ptr->nodes = NULL; if (list_append(part_list, part_ptr) == NULL) @@ -646,7 +641,7 @@ void pack_part(struct part_record *part_record_point, Buf buffer) */ int update_part(update_part_msg_t * part_desc) { - int error_code, i; + int error_code; struct part_record *part_ptr; if ((part_desc->name == NULL) || @@ -715,9 +710,7 @@ int update_part(update_part_msg_t * part_desc) if (part_desc->allow_groups != NULL) { xfree(part_ptr->allow_groups); - i = strlen(part_desc->allow_groups) + 1; - part_ptr->allow_groups = xmalloc(i); - strcpy(part_ptr->allow_groups, part_desc->allow_groups); + part_ptr->allow_groups = xstrdup(part_desc->allow_groups); info("update_part: setting allow_groups to %s for partition %s", part_desc->allow_groups, part_desc->name); xfree(part_ptr->allow_uids); @@ -728,9 +721,7 @@ int update_part(update_part_msg_t * part_desc) if (part_desc->nodes != NULL) { char *backup_node_list; backup_node_list = part_ptr->nodes; - i = strlen(part_desc->nodes) + 1; - part_ptr->nodes = xmalloc(i); - strcpy(part_ptr->nodes, part_desc->nodes); + part_ptr->nodes = xstrdup(part_desc->nodes); error_code = _build_part_bitmap(part_ptr); if (error_code) { @@ -819,10 +810,7 @@ uid_t *_get_groups_members(char *group_names) if (group_names == NULL) return NULL; - - i = strlen(group_names) + 1; - tmp_names = xmalloc(i); - strcpy(tmp_names, group_names); + tmp_names = xstrdup(group_names); one_group_name = strtok_r(tmp_names, ",", &name_ptr); while (one_group_name) {