Skip to content
Snippets Groups Projects
Commit 84a0333e authored by Moe Jette's avatar Moe Jette
Browse files

Strip brackets off of allocated cores string built for SPANK.

Fix memory leak in allocated cores string logic.
Add check for malloc failure in  allocated cores string logic.
parent 5d46cd59
No related branches found
No related tags found
No related merge requests found
...@@ -1119,7 +1119,7 @@ char* ...@@ -1119,7 +1119,7 @@ char*
format_core_allocs(slurm_cred_t cred, char *node_name) format_core_allocs(slurm_cred_t cred, char *node_name)
{ {
bitstr_t *core_bitmap; bitstr_t *core_bitmap;
char *str = NULL; char str[1024], *bracket_ptr;
hostset_t hset = NULL; hostset_t hset = NULL;
int host_index = -1; int host_index = -1;
uint32_t i, j, i_first_bit=0, i_last_bit=0; uint32_t i, j, i_first_bit=0, i_last_bit=0;
...@@ -1134,6 +1134,7 @@ format_core_allocs(slurm_cred_t cred, char *node_name) ...@@ -1134,6 +1134,7 @@ format_core_allocs(slurm_cred_t cred, char *node_name)
if ((host_index < 0) || (host_index >= cred->job_nhosts)) { if ((host_index < 0) || (host_index >= cred->job_nhosts)) {
error("Invalid host_index %d for job %u", error("Invalid host_index %d for job %u",
host_index, cred->jobid); host_index, cred->jobid);
hostset_destroy(hset);
return NULL; return NULL;
} }
host_index++; /* change from 0-origin to 1-origin */ host_index++; /* change from 0-origin to 1-origin */
...@@ -1155,16 +1156,28 @@ format_core_allocs(slurm_cred_t cred, char *node_name) ...@@ -1155,16 +1156,28 @@ format_core_allocs(slurm_cred_t cred, char *node_name)
} }
core_bitmap = bit_alloc(i_last_bit - i_first_bit); core_bitmap = bit_alloc(i_last_bit - i_first_bit);
if (core_bitmap == NULL) {
error("bit_alloc malloc failure");
hostset_destroy(hset);
return NULL;
}
for (i = i_first_bit, j = 0; i < i_last_bit; i++, j++) { for (i = i_first_bit, j = 0; i < i_last_bit; i++, j++) {
if (bit_test(cred->core_bitmap, i)) if (bit_test(cred->core_bitmap, i))
bit_set(core_bitmap, j); bit_set(core_bitmap, j);
} }
str = xmalloc(1024); bit_fmt(str, sizeof(str), core_bitmap);
bit_fmt(str, 1024, core_bitmap);
bit_free(core_bitmap); bit_free(core_bitmap);
hostset_destroy(hset);
if (str[0] != '[')
return xstrdup(str);
return str; /* strip off brackets */
bracket_ptr = strchr(str, ']');
if (bracket_ptr)
bracket_ptr[0] = '\0';
return xstrdup(str+1);
} }
void void
......
...@@ -294,7 +294,9 @@ int slurm_cred_get_signature(slurm_cred_t cred, char **datap, ...@@ -294,7 +294,9 @@ int slurm_cred_get_signature(slurm_cred_t cred, char **datap,
/* /*
* Retrieve the set of cores that were allocated to the job and format them * Retrieve the set of cores that were allocated to the job and format them
* in the List Format (e.g., "0-2,7,12-14") * in the List Format (e.g., "0-2,7,12-14").
*
* NOTE: caller must xfree the returned string.
*/ */
char* format_core_allocs(slurm_cred_t cred, char *node_name); char* format_core_allocs(slurm_cred_t cred, char *node_name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment