From 0d9e8e37df55129c3ca340ec7e7be842d5d6c5e2 Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Wed, 15 Nov 2006 00:02:40 +0000 Subject: [PATCH] Plug some memory leaks. --- src/plugins/select/cons_res/select_cons_res.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/plugins/select/cons_res/select_cons_res.c b/src/plugins/select/cons_res/select_cons_res.c index d2de313ee70..8bff46937bd 100644 --- a/src/plugins/select/cons_res/select_cons_res.c +++ b/src/plugins/select/cons_res/select_cons_res.c @@ -453,7 +453,11 @@ static void _xfree_select_cr_job(struct select_cr_job *job) if (job == NULL) return; - xfree(job->host); + if (job->host) { + for (i=0; i<job->nhosts; i++) + xfree(job->host[i]); + xfree(job->host); + } xfree(job->cpus); xfree(job->alloc_lps); xfree(job->alloc_sockets); @@ -985,6 +989,9 @@ static int _cr_unpack_job(struct select_cr_job *job, Buf buffer) nhosts = job->nhosts; safe_unpackstr_array(&job->host, &len16, buffer); + if (len16 != nhosts) + goto unpack_error; + safe_unpack16_array(&job->cpus, &len32, buffer); safe_unpack16_array(&job->alloc_lps, &len32, buffer); safe_unpack16_array(&job->alloc_sockets, &len32, buffer); @@ -1028,6 +1035,7 @@ static int _cr_unpack_job(struct select_cr_job *job, Buf buffer) return 0; unpack_error: + _xfree_select_cr_job(job); xfree(bit_fmt); return -1; } @@ -1279,11 +1287,12 @@ extern int select_p_node_init(struct node_record *node_ptr, int node_cnt) return SLURM_ERROR; } + /* completely rebuild node data */ + _xfree_select_nodes(select_node_ptr, select_node_cnt); select_node_cnt = node_cnt; select_node_ptr = xmalloc(sizeof(struct node_cr_record) * select_node_cnt); - for (i = 0; i < select_node_cnt; i++) { select_node_ptr[i].node_ptr = &node_ptr[i]; select_node_ptr[i].name = xstrdup(node_ptr[i].name); @@ -1645,7 +1654,11 @@ extern int select_p_job_test(struct job_record *job_ptr, bitstr_t * bitmap, for (i = 0; i < node_record_count; i++) { if (bit_test(bitmap, i) == 0) continue; - job->host[j] = node_record_table_ptr[i].name; + if (j >= job->nhosts) { + error("select_cons_res: job nhosts too small\n"); + break; + } + job->host[j] = xstrdup(node_record_table_ptr[i].name); job->cpus[j] = node_record_table_ptr[i].cpus; job->alloc_lps[j] = 0; job->alloc_sockets[j] = 0; -- GitLab