From 82d56f6d60cd618710291f599e37000359471227 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 7 Mar 2008 21:44:08 +0000
Subject: [PATCH] fix memory leak

---
 src/common/slurm_protocol_defs.c |  4 ++--
 src/common/slurm_protocol_pack.c |  4 ++--
 src/slurmctld/node_mgr.c         |  4 ++--
 src/slurmctld/read_config.c      | 18 ++++++++++++++++--
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/common/slurm_protocol_defs.c b/src/common/slurm_protocol_defs.c
index dbdb6d0417b..4d742609ff2 100644
--- a/src/common/slurm_protocol_defs.c
+++ b/src/common/slurm_protocol_defs.c
@@ -279,10 +279,10 @@ void slurm_free_node_registration_status_msg(
 	slurm_node_registration_status_msg_t * msg)
 {
 	if (msg) {
-		xfree(msg->node_name);
 		xfree(msg->arch);
-		xfree(msg->os);
 		xfree(msg->job_id);
+		xfree(msg->node_name);
+		xfree(msg->os);
 		xfree(msg->step_id);
 		if (msg->startup)
 			switch_g_free_node_info(&msg->switch_nodeinfo);
diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c
index 211bb3cf9be..0cd61f3b95a 100644
--- a/src/common/slurm_protocol_pack.c
+++ b/src/common/slurm_protocol_pack.c
@@ -1200,10 +1200,10 @@ _unpack_node_registration_status_msg(slurm_node_registration_status_msg_t
 	return SLURM_SUCCESS;
 
 unpack_error:
-	xfree(node_reg_ptr->node_name);
 	xfree(node_reg_ptr->arch);
-	xfree(node_reg_ptr->os);
 	xfree(node_reg_ptr->job_id);
+	xfree(node_reg_ptr->node_name);
+	xfree(node_reg_ptr->os);
 	xfree(node_reg_ptr->step_id);
 	switch_g_free_node_info(&node_reg_ptr->switch_nodeinfo);
 	xfree(node_reg_ptr);
diff --git a/src/slurmctld/node_mgr.c b/src/slurmctld/node_mgr.c
index 4af3e18c829..60439a54127 100644
--- a/src/slurmctld/node_mgr.c
+++ b/src/slurmctld/node_mgr.c
@@ -649,10 +649,10 @@ int init_node_conf (void)
 	int i;
 
 	for (i=0; i<node_record_count; i++) {
-		xfree(node_record_table_ptr[i].name);
 		xfree(node_record_table_ptr[i].arch);
 		xfree(node_record_table_ptr[i].comm_name);
 		xfree(node_record_table_ptr[i].features);
+		xfree(node_record_table_ptr[i].name);
 		xfree(node_record_table_ptr[i].os);
 		xfree(node_record_table_ptr[i].part_pptr);
 		xfree(node_record_table_ptr[i].reason);
@@ -2343,10 +2343,10 @@ void node_fini(void)
 	}
 
 	for (i=0; i< node_record_count; i++) {
-		xfree(node_record_table_ptr[i].name);
 		xfree(node_record_table_ptr[i].arch);
 		xfree(node_record_table_ptr[i].comm_name);
 		xfree(node_record_table_ptr[i].features);
+		xfree(node_record_table_ptr[i].name);
 		xfree(node_record_table_ptr[i].os);
 		xfree(node_record_table_ptr[i].part_pptr);
 		xfree(node_record_table_ptr[i].reason);
diff --git a/src/slurmctld/read_config.c b/src/slurmctld/read_config.c
index 5913e70d7fa..e40f38646c9 100644
--- a/src/slurmctld/read_config.c
+++ b/src/slurmctld/read_config.c
@@ -711,7 +711,9 @@ int read_slurm_conf(int recover)
 	old_node_record_count = node_record_count;
 	old_node_table_ptr    = node_record_table_ptr;
 	for (i=0; i<node_record_count; i++) {
+		xfree(old_node_table_ptr[i].arch);
 		xfree(old_node_table_ptr[i].features);
+		xfree(old_node_table_ptr[i].os);
 		old_node_table_ptr[i].features = xstrdup(
 			old_node_table_ptr[i].config_ptr->feature);
 	}
@@ -860,6 +862,16 @@ static void _restore_node_state(struct node_record *old_node_table_ptr,
 			node_ptr->features = old_node_table_ptr[i].features;
 			old_node_table_ptr[i].features = NULL;
 		}
+		if (old_node_table_ptr[i].arch) {
+			xfree(node_ptr->arch);
+			node_ptr->arch = old_node_table_ptr[i].arch;
+			old_node_table_ptr[i].arch = NULL;
+		}
+		if (old_node_table_ptr[i].os) {
+			xfree(node_ptr->os);
+			node_ptr->os = old_node_table_ptr[i].os;
+			old_node_table_ptr[i].os = NULL;
+		}
 	}
 }
 
@@ -870,10 +882,12 @@ static void _purge_old_node_state(struct node_record *old_node_table_ptr,
 	int i;
 
 	for (i = 0; i < old_node_record_count; i++) {
-		xfree(old_node_table_ptr[i].name);
+		xfree(old_node_table_ptr[i].arch);
 		xfree(old_node_table_ptr[i].comm_name);
-		xfree(old_node_table_ptr[i].part_pptr);
 		xfree(old_node_table_ptr[i].features);
+		xfree(old_node_table_ptr[i].name);
+		xfree(old_node_table_ptr[i].os);
+		xfree(old_node_table_ptr[i].part_pptr);
 		xfree(old_node_table_ptr[i].reason);
 	}
 	xfree(old_node_table_ptr);
-- 
GitLab