From 3807f654b7accdfd088b0804d73cb5699eec919f Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Thu, 13 May 2004 22:07:13 +0000 Subject: [PATCH] Add tests for malloc failure (NULL return values) for bit_copy and bit_alloc calls. --- src/slurmctld/job_mgr.c | 4 +++- src/slurmctld/node_scheduler.c | 13 +++++++++++-- src/slurmctld/partition_mgr.c | 6 ++++-- src/slurmctld/read_config.c | 10 +++++----- src/slurmctld/step_mgr.c | 7 ++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/slurmctld/job_mgr.c b/src/slurmctld/job_mgr.c index a485d5e928f..44b70deee42 100644 --- a/src/slurmctld/job_mgr.c +++ b/src/slurmctld/job_mgr.c @@ -6,7 +6,7 @@ ***************************************************************************** * Copyright (C) 2002 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). - * Written by Moe Jette <jette1@llnl.gov> + * Written by Morris Jette <jette1@llnl.gov> * UCRL-CODE-2002-040. * * This file is part of SLURM, a resource management program. @@ -1553,6 +1553,8 @@ static int _job_create(job_desc_msg_t * job_desc, uint32_t * new_job_id, bitstr_t *tmp_bitmap = NULL; bitoff_t first_set; tmp_bitmap = bit_copy(exc_bitmap); + if (tmp_bitmap == NULL) + fatal("bit_copy malloc failure"); bit_and(tmp_bitmap, req_bitmap); first_set = bit_ffs(tmp_bitmap); FREE_NULL_BITMAP(tmp_bitmap); diff --git a/src/slurmctld/node_scheduler.c b/src/slurmctld/node_scheduler.c index 11466df9b3e..2d5b29449b6 100644 --- a/src/slurmctld/node_scheduler.c +++ b/src/slurmctld/node_scheduler.c @@ -4,7 +4,7 @@ ***************************************************************************** * Copyright (C) 2002 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). - * Written by Moe Jette <jette1@llnl.gov> + * Written by Morris Jette <jette1@llnl.gov> * UCRL-CODE-2002-040. * * This file is part of SLURM, a resource management program. @@ -527,6 +527,9 @@ _node_load_bitmaps(bitstr_t * bitmap, bitstr_t ** no_load_bit, bitstr_t *bitmap1 = bit_alloc(size); bitstr_t *bitmap2 = bit_alloc(size); + if ((bitmap0 == NULL) || (bitmap1 == NULL) || (bitmap2 == NULL)) + fatal("bit_alloc malloc failure"); + for (i = 0; i < size; i++) { if (!bit_test(bitmap, i)) continue; @@ -740,6 +743,8 @@ _pick_best_nodes(struct node_set *node_set_ptr, int node_set_size, if (!runable_avail) { FREE_NULL_BITMAP(avail_bitmap); avail_bitmap = bit_copy(total_bitmap); + if (avail_bitmap == NULL) + fatal("bit_copy malloc failure"); bit_and(avail_bitmap, avail_node_bitmap); pick_code = _pick_best_layout( avail_bitmap, @@ -876,6 +881,8 @@ int select_nodes(struct job_record *job_ptr, bool test_only) goto cleanup; } req_bitmap = bit_copy(job_ptr->details->req_node_bitmap); + if (req_bitmap == NULL) + fatal("bit_copy malloc failure"); } /* pick the nodes providing a best-fit */ @@ -975,6 +982,8 @@ static int _build_node_list(struct job_record *job_ptr, node_set_ptr[node_set_inx+1].my_bitmap = NULL; if (detail_ptr->exc_node_bitmap) { exc_node_mask = bit_copy(detail_ptr->exc_node_bitmap); + if (exc_node_mask == NULL) + fatal("bit_copy malloc failure"); bit_not(exc_node_mask); } @@ -1009,7 +1018,7 @@ static int _build_node_list(struct job_record *job_ptr, node_set_ptr[node_set_inx].my_bitmap = bit_copy(config_ptr->node_bitmap); if (node_set_ptr[node_set_inx].my_bitmap == NULL) - fatal("bit_copy memory allocation failure"); + fatal("bit_copy malloc failure"); bit_and(node_set_ptr[node_set_inx].my_bitmap, part_ptr->node_bitmap); if (exc_node_mask) diff --git a/src/slurmctld/partition_mgr.c b/src/slurmctld/partition_mgr.c index 18793bd2193..592ffcd55f8 100644 --- a/src/slurmctld/partition_mgr.c +++ b/src/slurmctld/partition_mgr.c @@ -5,7 +5,7 @@ ***************************************************************************** * Copyright (C) 2002 The Regents of the University of California. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). - * Written by Moe Jette <jette@llnl.gov> et. al. + * Written by Morris Jette <jette@llnl.gov> et. al. * UCRL-CODE-2002-040. * * This file is part of SLURM, a resource management program. @@ -95,10 +95,12 @@ static int _build_part_bitmap(struct part_record *part_ptr) part_ptr->node_bitmap = (bitstr_t *) bit_alloc(node_record_count); if (part_ptr->node_bitmap == NULL) - fatal("bit_alloc memory allocation failure"); + fatal("bit_alloc malloc failure"); old_bitmap = NULL; } else { old_bitmap = bit_copy(part_ptr->node_bitmap); + if (old_bitmap == NULL) + fatal("bit_copy malloc failure"); bit_nclear(part_ptr->node_bitmap, 0, node_record_count - 1); } diff --git a/src/slurmctld/read_config.c b/src/slurmctld/read_config.c index feea105fdf9..bf31f95c6c3 100644 --- a/src/slurmctld/read_config.c +++ b/src/slurmctld/read_config.c @@ -116,7 +116,7 @@ static int _build_bitmaps(void) if ((idle_node_bitmap == NULL) || (avail_node_bitmap == NULL) || (share_node_bitmap == NULL)) - fatal ("memory allocation failure"); + fatal ("bit_alloc malloc failure"); /* Set all bits, all nodes initially available for sharing */ bit_nset(share_node_bitmap, 0, (node_record_count-1)); @@ -131,7 +131,7 @@ static int _build_bitmaps(void) config_ptr->node_bitmap = (bitstr_t *) bit_alloc(node_record_count); if (config_ptr->node_bitmap == NULL) - fatal ("memory allocation failure"); + fatal ("bit_alloc malloc failure"); } list_iterator_destroy(config_iterator); @@ -146,7 +146,7 @@ static int _build_bitmaps(void) continue; tmp_bits = bit_copy(job_ptr->node_bitmap); if (tmp_bits == NULL) - fatal ("memory allocation failure"); + fatal ("bit_copy malloc failure"); bit_not(tmp_bits); bit_and(share_node_bitmap, tmp_bits); bit_free(tmp_bits); @@ -182,7 +182,7 @@ static int _build_bitmaps(void) /* scan partition table and identify nodes in each */ all_part_node_bitmap = (bitstr_t *) bit_alloc(node_record_count); if (all_part_node_bitmap == NULL) - fatal ("memory allocation failure"); + fatal ("bit_alloc malloc failure"); part_iterator = list_iterator_create(part_list); if (part_iterator == NULL) fatal ("memory allocation failure"); @@ -192,7 +192,7 @@ static int _build_bitmaps(void) part_ptr->node_bitmap = (bitstr_t *) bit_alloc(node_record_count); if (part_ptr->node_bitmap == NULL) - fatal ("memory allocation failure"); + fatal ("bit_alloc malloc failure"); /* check for each node in the partition */ if ((part_ptr->nodes == NULL) || (part_ptr->nodes[0] == '\0')) diff --git a/src/slurmctld/step_mgr.c b/src/slurmctld/step_mgr.c index 3dae0c35bd7..82e6a83ef29 100644 --- a/src/slurmctld/step_mgr.c +++ b/src/slurmctld/step_mgr.c @@ -351,6 +351,8 @@ _pick_step_nodes (struct job_record *job_ptr, step_specs *step_spec ) { return NULL; nodes_avail = bit_copy (job_ptr->node_bitmap); + if (nodes_avail == NULL) + fatal("bit_copy malloc failure"); bit_and (nodes_avail, avail_node_bitmap); if ( step_spec->node_count == INFINITE) /* use all nodes */ @@ -391,8 +393,11 @@ _pick_step_nodes (struct job_record *job_ptr, step_specs *step_spec ) { bit_and (nodes_avail, relative_nodes); bit_free (relative_nodes); } - else + else { nodes_picked = bit_alloc (bit_size (nodes_avail) ); + if (nodes_picked == NULL) + fatal("bit_alloc malloc failure"); + } /* if user specifies step needs a specific processor count and */ /* all nodes have the same processor count, just translate this to */ -- GitLab