From 155a65a4a155450f1d938786a79d7beb11c69d3e Mon Sep 17 00:00:00 2001 From: Morris Jette <jette@schedmd.com> Date: Mon, 9 Jan 2017 16:39:39 -0700 Subject: [PATCH] Fix more memory problems reported by Coverity 3 places where a string pointer referenced an out-of-scope memory location 1 memory leak and 1 unterminated string --- .../accounting_storage/mysql/as_mysql_archive.c | 10 ++++++---- .../accounting_storage/mysql/as_mysql_assoc.c | 7 ++++--- .../accounting_storage/mysql/as_mysql_job.c | 15 ++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/plugins/accounting_storage/mysql/as_mysql_archive.c b/src/plugins/accounting_storage/mysql/as_mysql_archive.c index ba808e3cf51..c5227051067 100644 --- a/src/plugins/accounting_storage/mysql/as_mysql_archive.c +++ b/src/plugins/accounting_storage/mysql/as_mysql_archive.c @@ -2570,8 +2570,8 @@ extern int as_mysql_jobacct_process_archive_load( arch_rec->archive_file); error_code = ENOENT; } else { - data_allocated = BUF_SIZE; - data = xmalloc(data_allocated); + data_allocated = BUF_SIZE + 1; + data = xmalloc_nz(data_allocated); while (1) { data_read = read(state_fd, &data[data_size], BUF_SIZE); @@ -2583,11 +2583,13 @@ extern int as_mysql_jobacct_process_archive_load( arch_rec->archive_file); break; } - } else if (data_read == 0) /* eof */ + } + data[data_read] = '\0'; + if (data_read == 0) /* eof */ break; data_size += data_read; data_allocated += data_read; - xrealloc(data, data_allocated); + xrealloc_nz(data, data_allocated); } close(state_fd); } diff --git a/src/plugins/accounting_storage/mysql/as_mysql_assoc.c b/src/plugins/accounting_storage/mysql/as_mysql_assoc.c index 168a888eda4..3086805c0a8 100644 --- a/src/plugins/accounting_storage/mysql/as_mysql_assoc.c +++ b/src/plugins/accounting_storage/mysql/as_mysql_assoc.c @@ -1588,18 +1588,18 @@ static int _process_modify_assoc_results(mysql_conn_t *mysql_conn, } xfree(tmp_qos); - set_qos_vals=1; + set_qos_vals = 1; } - if (account_type) + if (account_type) { _modify_unset_users(mysql_conn, mod_assoc, row[MASSOC_ACCT], lft, rgt, ret_list, moved_parent); - else if ((assoc->is_def == 1) && row[MASSOC_USER][0]) { + } else if ((assoc->is_def == 1) && row[MASSOC_USER][0]) { /* Use fresh one here so we don't have to worry about dealing with bad values. */ @@ -1613,6 +1613,7 @@ static int _process_modify_assoc_results(mysql_conn_t *mysql_conn, mysql_conn, &tmp_assoc, &reset_query, moved_parent ? 0 : 1)) != SLURM_SUCCESS) { + slurmdb_destroy_assoc_rec(mod_assoc); xfree(reset_query); goto end_it; } diff --git a/src/plugins/accounting_storage/mysql/as_mysql_job.c b/src/plugins/accounting_storage/mysql/as_mysql_job.c index 33a90e35982..8de87239e21 100644 --- a/src/plugins/accounting_storage/mysql/as_mysql_job.c +++ b/src/plugins/accounting_storage/mysql/as_mysql_job.c @@ -240,11 +240,12 @@ no_wckeyid: extern int as_mysql_job_start(mysql_conn_t *mysql_conn, struct job_record *job_ptr) { - int rc=SLURM_SUCCESS; + int rc = SLURM_SUCCESS; char *nodes = NULL, *jname = NULL, *node_inx = NULL; int track_steps = 0; - char *block_id = NULL, *partition = NULL, - *gres_req = NULL, *gres_alloc = NULL; + char *block_id = NULL, *partition = NULL; + char *gres_req = NULL, *gres_alloc = NULL; + char temp_bit[BUF_SIZE]; char *query = NULL; int reinit = 0; time_t begin_time, check_time, start_time, submit_time; @@ -421,8 +422,6 @@ no_rollup_change: node_cnt = job_ptr->total_nodes; node_inx = job_ptr->network; } else { - char temp_bit[BUF_SIZE]; - if (job_ptr->node_bitmap) { node_inx = bit_fmt(temp_bit, sizeof(temp_bit), job_ptr->node_bitmap); @@ -942,7 +941,8 @@ extern int as_mysql_step_start(mysql_conn_t *mysql_conn, struct step_record *step_ptr) { int tasks = 0, nodes = 0, task_dist = 0; - int rc=SLURM_SUCCESS; + int rc = SLURM_SUCCESS; + char temp_bit[BUF_SIZE]; char node_list[BUFFER_SIZE]; char *node_inx = NULL, *step_name = NULL; time_t start_time, submit_time; @@ -979,8 +979,6 @@ extern int as_mysql_step_start(mysql_conn_t *mysql_conn, task_dist = step_ptr->step_layout->task_dist; node_inx = step_ptr->network; } else if (step_ptr->step_id == SLURM_BATCH_SCRIPT) { - char temp_bit[BUF_SIZE]; - if (step_ptr->step_node_bitmap) { node_inx = bit_fmt(temp_bit, sizeof(temp_bit), step_ptr->step_node_bitmap); @@ -998,7 +996,6 @@ extern int as_mysql_step_start(mysql_conn_t *mysql_conn, TRES_NODE, 1); } else { char *ionodes = NULL, *temp_nodes = NULL; - char temp_bit[BUF_SIZE]; if (step_ptr->step_node_bitmap) { node_inx = bit_fmt(temp_bit, sizeof(temp_bit), -- GitLab