From df1b0766f52444924f9680cbb00355dbd0bf2067 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Fri, 2 Nov 2012 11:49:29 -0700
Subject: [PATCH] More mem leak fixes for core reservations

---
 src/plugins/sched/backfill/backfill.c  |  3 ++-
 src/plugins/sched/builtin/builtin.c    |  6 +++++-
 src/plugins/sched/wiki2/job_will_run.c | 12 ++++++++++++
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/plugins/sched/backfill/backfill.c b/src/plugins/sched/backfill/backfill.c
index df438639981..f210b57cf49 100644
--- a/src/plugins/sched/backfill/backfill.c
+++ b/src/plugins/sched/backfill/backfill.c
@@ -701,9 +701,9 @@ static int _attempt_backfill(void)
 		/* Determine impact of any resource reservations */
 		later_start = now;
  TRY_LATER:	FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		start_res   = later_start;
 		later_start = 0;
-		exc_core_bitmap = NULL;
 		j = job_test_resv(job_ptr, &start_res, true, &avail_bitmap,
 				  &exc_core_bitmap);
 		if (j != SLURM_SUCCESS) {
@@ -890,6 +890,7 @@ static int _attempt_backfill(void)
 	xfree(uid);
 	xfree(njobs);
 	FREE_NULL_BITMAP(avail_bitmap);
+	FREE_NULL_BITMAP(exc_core_bitmap);
 	FREE_NULL_BITMAP(resv_bitmap);
 
 	for (i=0; ; ) {
diff --git a/src/plugins/sched/builtin/builtin.c b/src/plugins/sched/builtin/builtin.c
index b581a0d5b35..047b602e9d3 100644
--- a/src/plugins/sched/builtin/builtin.c
+++ b/src/plugins/sched/builtin/builtin.c
@@ -196,8 +196,11 @@ static void _compute_start_times(void)
 
 		j = job_test_resv(job_ptr, &now, true, &avail_bitmap,
 				  &exc_core_bitmap);
-		if (j != SLURM_SUCCESS)
+		if (j != SLURM_SUCCESS) {
+			FREE_NULL_BITMAP(avail_bitmap);
+			FREE_NULL_BITMAP(exc_core_bitmap);
 			continue;
+		}
 
 		rc = select_g_job_test(job_ptr, avail_bitmap,
 				       min_nodes, max_nodes, req_nodes,
@@ -223,6 +226,7 @@ static void _compute_start_times(void)
 			last_job_alloc = job_ptr->start_time + time_limit;
 		}
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 
 		if ((time(NULL) - sched_start) >= sched_timeout) {
 			debug("backfill: loop taking to long, breaking out");
diff --git a/src/plugins/sched/wiki2/job_will_run.c b/src/plugins/sched/wiki2/job_will_run.c
index 13eeeedebaf..e2010a47461 100644
--- a/src/plugins/sched/wiki2/job_will_run.c
+++ b/src/plugins/sched/wiki2/job_will_run.c
@@ -181,6 +181,7 @@ static char *	_will_run_test(uint32_t jobid, time_t start_time,
 		*err_msg = "Job denied access to reservation";
 		error("wiki: reservation access denied for job %u", jobid);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 	start_time = MAX(start_time, start_res);
@@ -199,6 +200,7 @@ static char *	_will_run_test(uint32_t jobid, time_t start_time,
 		error("wiki: no nodes in partition %s for job %u",
 			part_ptr->name, jobid);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 
@@ -210,6 +212,7 @@ static char *	_will_run_test(uint32_t jobid, time_t start_time,
 		error("wiki: job %u not runnable on hosts=%s",
 		      jobid, node_list);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 	if (job_ptr->details->exc_node_bitmap) {
@@ -225,6 +228,7 @@ static char *	_will_run_test(uint32_t jobid, time_t start_time,
 		error("wiki: job %u not runnable on hosts=%s",
 		      jobid, node_list);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 
@@ -246,6 +250,7 @@ static char *	_will_run_test(uint32_t jobid, time_t start_time,
 		error("wiki: job %u not runnable on hosts=%s",
 		      jobid, node_list);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 
@@ -287,6 +292,7 @@ static char *	_will_run_test(uint32_t jobid, time_t start_time,
 	/* Restore pending job's expected start time */
 	job_ptr->start_time = orig_start_time;
 	FREE_NULL_BITMAP(avail_bitmap);
+	FREE_NULL_BITMAP(exc_core_bitmap);
 	return reply_msg;
 }
 
@@ -465,6 +471,7 @@ static char *	_will_run_test2(uint32_t jobid, time_t start_time,
 		*err_msg = "Job denied access to reservation";
 		error("wiki: reservation access denied for job %u", jobid);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 	start_time = MAX(start_time, start_res);
@@ -483,6 +490,7 @@ static char *	_will_run_test2(uint32_t jobid, time_t start_time,
 		error("wiki: no nodes in partition %s for job %u",
 			part_ptr->name, jobid);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 
@@ -494,6 +502,7 @@ static char *	_will_run_test2(uint32_t jobid, time_t start_time,
 		error("wiki: job %u not runnable on hosts=%s",
 			jobid, node_list);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 	if (job_ptr->details->exc_node_bitmap) {
@@ -509,6 +518,7 @@ static char *	_will_run_test2(uint32_t jobid, time_t start_time,
 		error("wiki: job %u not runnable on hosts=%s",
 			jobid, node_list);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 
@@ -530,6 +540,7 @@ static char *	_will_run_test2(uint32_t jobid, time_t start_time,
 		error("wiki: job %u not runnable on hosts=%s",
 			jobid, node_list);
 		FREE_NULL_BITMAP(avail_bitmap);
+		FREE_NULL_BITMAP(exc_core_bitmap);
 		return NULL;
 	}
 
@@ -589,6 +600,7 @@ static char *	_will_run_test2(uint32_t jobid, time_t start_time,
 	job_ptr->start_time = orig_start_time;
 
 	FREE_NULL_BITMAP(avail_bitmap);
+	FREE_NULL_BITMAP(exc_core_bitmap);
 	return reply_msg;
 }
 
-- 
GitLab