From bb100dabe2bd2ae8c8b2a1fbfea6ad77d993e8f7 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 7 Mar 2008 21:50:25 +0000
Subject: [PATCH] fix a couple of possible memory leaks in freeing config info

---
 slurm/slurm.h.in                 | 22 ++++++-------
 src/common/read_config.c         | 56 +++++++++++++++++---------------
 src/common/slurm_protocol_defs.c | 35 ++++++++++----------
 src/common/slurm_protocol_pack.c | 12 ++++---
 4 files changed, 67 insertions(+), 58 deletions(-)

diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in
index b3be0a4bd91..dedb2dfdcd8 100644
--- a/slurm/slurm.h.in
+++ b/slurm/slurm.h.in
@@ -956,18 +956,18 @@ typedef struct slurm_ctl_conf {
 	char *job_acct_gather_type; /* job accounting gather type */
 	uint16_t job_acct_gather_freq; /* poll frequency for job accounting 
 					* gather plugins */
-	char *job_acct_storage_loc; /* job accounting storage log location */
-	char *job_acct_storage_type;	/* job accounting storage type */
-	char *job_acct_storage_user;	/* job accounting storage user */
 	char *job_acct_storage_host;	/* job accounting storage host */
+	char *job_acct_storage_loc; /* job accounting storage log location */
 	char *job_acct_storage_pass;	/* job accounting storage password */
 	uint32_t job_acct_storage_port;	/* job accounting storage port */
-	char *job_comp_loc;	/* job completion logging location */
-	char *job_comp_type;	/* job completion storage type */
-	char *job_comp_user;	/* job completion storage user */
+	char *job_acct_storage_type;	/* job accounting storage type */
+	char *job_acct_storage_user;	/* job accounting storage user */
 	char *job_comp_host;	/* job completion storage host */
+	char *job_comp_loc;	/* job completion logging location */
 	char *job_comp_pass;	/* job completion storage password */
 	uint32_t job_comp_port;	/* job completion storage port */
+	char *job_comp_type;	/* job completion storage type */
+	char *job_comp_user;	/* job completion storage user */
 	char *job_credential_private_key;	/* path to private key */
 	char *job_credential_public_certificate;/* path to public certificate*/
 	uint16_t job_file_append; /* if set, append to stdout/err file */
@@ -982,7 +982,7 @@ typedef struct slurm_ctl_conf {
 	                         * purged from in memory records */
 	char *mpi_default;	/* Default version of MPI in use */
 	uint16_t msg_timeout;	/* message timeout */
-	char *node_prefix;      /* prefix of nodes in partition only set in 
+	char *node_prefix;      /* prefix of nodes in partition, only set in 
 				   bluegene clusters NULL otherwise */
 	char *plugindir;	/* pathname to plugins */
 	char *plugstack;        /* pathname to plugin stack config file */
@@ -993,10 +993,10 @@ typedef struct slurm_ctl_conf {
 				          * be propagated */
         char *propagate_rlimits;/* Propagate (all/specific) resource limits */
         char *propagate_rlimits_except;/* Propagate all rlimits except these */
-	uint16_t ret2service;	/* 1 return DOWN node to service at 
-				 * registration */
 	uint16_t resume_rate;	/* nodes to make full power, per minute */
 	char *resume_program;	/* program to make nodes full power */
+	uint16_t ret2service;	/* 1 return DOWN node to service at 
+				 * registration */
 	char *sched_conf;	/* contents of scheduler plugin config file */
 	uint16_t sched_time_slice;	/* gang scheduler slice time, secs */
 	char *schedtype;	/* type of scheduler to use */
@@ -1016,17 +1016,17 @@ typedef struct slurm_ctl_conf {
 				 * on non-responding primarly controller */
 	uint16_t slurmd_debug;	/* slurmd logging level */
 	char *slurmd_logfile;	/* where slurmd error log gets written */
+	char *slurmd_pidfile;   /* where to put slurmd pidfile           */
 	uint32_t slurmd_port;	/* default communications port to slurmd */
 	char *slurmd_spooldir;	/* where slurmd put temporary state info */
-	char *slurmd_pidfile;   /* where to put slurmd pidfile           */
 	uint16_t slurmd_timeout;/* how long slurmctld waits for slurmd before 
 				 * considering node DOWN */
 	char *slurmdbd_addr;	/* comm path for Slurm DBD */
 	char * slurmdbd_auth_info;	/* Slurm DBD authentication info */
 	uint16_t slurmdbd_port;	/* port for Slurm DBD socket */
 	char *slurm_conf;	/* pathname of slurm config file */
-	char *srun_prolog;      /* srun prolog program */
 	char *srun_epilog;      /* srun epilog program */
+	char *srun_prolog;      /* srun prolog program */
 	char *state_save_location;/* pathname of slurmctld state save
 				 * directory */
 	char *suspend_exc_nodes;/* nodes to not make power saving */
diff --git a/src/common/read_config.c b/src/common/read_config.c
index 374494a3ee5..d8e9a7e0004 100644
--- a/src/common/read_config.c
+++ b/src/common/read_config.c
@@ -1072,22 +1072,23 @@ free_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr, bool purge_node_hash)
 	xfree (ctl_conf_ptr->backup_addr);
 	xfree (ctl_conf_ptr->backup_controller);
 	xfree (ctl_conf_ptr->checkpoint_type);
+	xfree (ctl_conf_ptr->cluster_name);
 	xfree (ctl_conf_ptr->control_addr);
 	xfree (ctl_conf_ptr->control_machine);
 	xfree (ctl_conf_ptr->crypto_type);
 	xfree (ctl_conf_ptr->epilog);
 	xfree (ctl_conf_ptr->health_check_program);
 	xfree (ctl_conf_ptr->job_acct_gather_type);
+	xfree (ctl_conf_ptr->job_acct_storage_host);
 	xfree (ctl_conf_ptr->job_acct_storage_loc);
+	xfree (ctl_conf_ptr->job_acct_storage_pass);
 	xfree (ctl_conf_ptr->job_acct_storage_type);
 	xfree (ctl_conf_ptr->job_acct_storage_user);
-	xfree (ctl_conf_ptr->job_acct_storage_host);
-	xfree (ctl_conf_ptr->job_acct_storage_pass);
+	xfree (ctl_conf_ptr->job_comp_host);
 	xfree (ctl_conf_ptr->job_comp_loc);
+	xfree (ctl_conf_ptr->job_comp_pass);
 	xfree (ctl_conf_ptr->job_comp_type);
 	xfree (ctl_conf_ptr->job_comp_user);
-	xfree (ctl_conf_ptr->job_comp_host);
-	xfree (ctl_conf_ptr->job_comp_pass);
 	xfree (ctl_conf_ptr->job_credential_private_key);
 	xfree (ctl_conf_ptr->job_credential_public_certificate);
 	xfree (ctl_conf_ptr->licenses);
@@ -1109,12 +1110,11 @@ free_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr, bool purge_node_hash)
 	xfree (ctl_conf_ptr->slurmctld_pidfile);
 	xfree (ctl_conf_ptr->slurmd_logfile);
 	xfree (ctl_conf_ptr->slurmd_pidfile);
-/*	xfree (ctl_conf_ptr->slurm_conf);	UNUSED HERE */
-	xfree (ctl_conf_ptr->srun_epilog);
-	xfree (ctl_conf_ptr->srun_prolog);
 	xfree (ctl_conf_ptr->slurmd_spooldir);
 	xfree (ctl_conf_ptr->slurmdbd_addr);
 	xfree (ctl_conf_ptr->slurmdbd_auth_info);
+	xfree (ctl_conf_ptr->srun_epilog);
+	xfree (ctl_conf_ptr->srun_prolog);
 	xfree (ctl_conf_ptr->state_save_location);
 	xfree (ctl_conf_ptr->suspend_exc_nodes);
 	xfree (ctl_conf_ptr->suspend_exc_parts);
@@ -1140,17 +1140,18 @@ void
 init_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr)
 {
 	ctl_conf_ptr->last_update		= time(NULL);
-	xfree (ctl_conf_ptr->authtype);
 	ctl_conf_ptr->cache_groups		= (uint16_t) NO_VAL;
-	xfree (ctl_conf_ptr->accounting_storage_type);
-	xfree (ctl_conf_ptr->accounting_storage_user);
 	xfree (ctl_conf_ptr->accounting_storage_host);
 	xfree (ctl_conf_ptr->accounting_storage_pass);
 	ctl_conf_ptr->accounting_storage_port             = 0;
-	xfree (ctl_conf_ptr->checkpoint_type);
-	xfree (ctl_conf_ptr->cluster_name);
+	xfree (ctl_conf_ptr->accounting_storage_type);
+	xfree (ctl_conf_ptr->accounting_storage_user);
+	xfree (ctl_conf_ptr->authtype);
 	xfree (ctl_conf_ptr->backup_addr);
 	xfree (ctl_conf_ptr->backup_controller);
+	ctl_conf_ptr->cache_groups		= 0;
+	xfree (ctl_conf_ptr->checkpoint_type);
+	xfree (ctl_conf_ptr->cluster_name);
 	xfree (ctl_conf_ptr->control_addr);
 	xfree (ctl_conf_ptr->control_machine);
 	xfree (ctl_conf_ptr->crypto_type);
@@ -1159,23 +1160,24 @@ init_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr)
 	ctl_conf_ptr->epilog_msg_time		= (uint32_t) NO_VAL;
 	ctl_conf_ptr->fast_schedule		= (uint16_t) NO_VAL;
 	ctl_conf_ptr->first_job_id		= (uint32_t) NO_VAL;
+	ctl_conf_ptr->get_env_timeout		= 0;
 	ctl_conf_ptr->health_check_interval	= 0;
 	xfree(ctl_conf_ptr->health_check_program);
 	ctl_conf_ptr->inactive_limit		= (uint16_t) NO_VAL;
 	xfree (ctl_conf_ptr->job_acct_gather_type);
 	ctl_conf_ptr->job_acct_gather_freq             = 0;
-	xfree (ctl_conf_ptr->job_acct_storage_loc);
-	xfree (ctl_conf_ptr->job_acct_storage_type);
-	xfree (ctl_conf_ptr->job_acct_storage_user);
 	xfree (ctl_conf_ptr->job_acct_storage_host);
+	xfree (ctl_conf_ptr->job_acct_storage_loc);
 	xfree (ctl_conf_ptr->job_acct_storage_pass);
 	ctl_conf_ptr->job_acct_storage_port             = 0;
-	xfree (ctl_conf_ptr->job_comp_loc);
-	xfree (ctl_conf_ptr->job_comp_type);
-	xfree (ctl_conf_ptr->job_comp_user);
+	xfree (ctl_conf_ptr->job_acct_storage_type);
+	xfree (ctl_conf_ptr->job_acct_storage_user);
 	xfree (ctl_conf_ptr->job_comp_host);
+	xfree (ctl_conf_ptr->job_comp_loc);
 	xfree (ctl_conf_ptr->job_comp_pass);
 	ctl_conf_ptr->job_comp_port             = 0;
+	xfree (ctl_conf_ptr->job_comp_type);
+	xfree (ctl_conf_ptr->job_comp_user);
 	xfree (ctl_conf_ptr->job_credential_private_key);
 	xfree (ctl_conf_ptr->job_credential_public_certificate);
 	ctl_conf_ptr->job_file_append		= (uint16_t) NO_VAL;
@@ -1189,21 +1191,23 @@ init_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr)
 	xfree (ctl_conf_ptr->mpi_default);
 	ctl_conf_ptr->msg_timeout		= (uint16_t) NO_VAL;
 	ctl_conf_ptr->next_job_id		= (uint32_t) NO_VAL;
+	xfree (ctl_conf_ptr->node_prefix);
 	xfree (ctl_conf_ptr->plugindir);
 	xfree (ctl_conf_ptr->plugstack);
 	ctl_conf_ptr->private_data              = 0;
 	xfree (ctl_conf_ptr->proctrack_type);
 	xfree (ctl_conf_ptr->prolog);
 	ctl_conf_ptr->propagate_prio_process	= (uint16_t) NO_VAL;
-	xfree (ctl_conf_ptr->propagate_rlimits_except);
 	xfree (ctl_conf_ptr->propagate_rlimits);
+	xfree (ctl_conf_ptr->propagate_rlimits_except);
 	xfree (ctl_conf_ptr->resume_program);
 	ctl_conf_ptr->resume_rate		= (uint16_t) NO_VAL;
 	ctl_conf_ptr->ret2service		= (uint16_t) NO_VAL;
+	xfree( ctl_conf_ptr->sched_conf );
 	ctl_conf_ptr->sched_time_slice		= (uint16_t) NO_VAL;
+	xfree( ctl_conf_ptr->schedtype );
 	ctl_conf_ptr->schedport			= (uint16_t) NO_VAL;
 	ctl_conf_ptr->schedrootfltr		= (uint16_t) NO_VAL;
-	xfree( ctl_conf_ptr->schedtype );
 	xfree( ctl_conf_ptr->select_type );
 	ctl_conf_ptr->select_type_param         = (uint16_t) NO_VAL;
 	ctl_conf_ptr->slurm_user_id		= (uint16_t) NO_VAL; 
@@ -1222,6 +1226,8 @@ init_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr)
 	xfree (ctl_conf_ptr->slurmdbd_addr);
 	xfree (ctl_conf_ptr->slurmdbd_auth_info);
 	ctl_conf_ptr->slurmdbd_port		= (uint16_t) NO_VAL;
+	xfree (ctl_conf_ptr->srun_prolog);
+	xfree (ctl_conf_ptr->srun_epilog);
 	xfree (ctl_conf_ptr->state_save_location);
 	xfree (ctl_conf_ptr->suspend_exc_nodes);
 	xfree (ctl_conf_ptr->suspend_exc_parts);
@@ -1230,17 +1236,15 @@ init_slurm_conf (slurm_ctl_conf_t *ctl_conf_ptr)
 	ctl_conf_ptr->suspend_time		= (uint16_t) NO_VAL;
 	xfree (ctl_conf_ptr->switch_type);
 	xfree (ctl_conf_ptr->task_epilog);
-	xfree (ctl_conf_ptr->task_prolog);
 	xfree (ctl_conf_ptr->task_plugin);
+	ctl_conf_ptr->task_plugin_param		= 0;
+	xfree (ctl_conf_ptr->task_prolog);
 	xfree (ctl_conf_ptr->tmp_fs);
-	ctl_conf_ptr->wait_time			= (uint16_t) NO_VAL;
-	xfree (ctl_conf_ptr->srun_prolog);
-	xfree (ctl_conf_ptr->srun_epilog);
-	xfree (ctl_conf_ptr->node_prefix);
 	ctl_conf_ptr->tree_width       		= (uint16_t) NO_VAL;
-	ctl_conf_ptr->use_pam			= 0;
 	xfree (ctl_conf_ptr->unkillable_program);
 	ctl_conf_ptr->unkillable_timeout        = (uint16_t) NO_VAL;
+	ctl_conf_ptr->use_pam			= 0;
+	ctl_conf_ptr->wait_time			= (uint16_t) NO_VAL;
 
 	_free_name_hashtbl();
 	_init_name_hashtbl();
diff --git a/src/common/slurm_protocol_defs.c b/src/common/slurm_protocol_defs.c
index 4d742609ff2..0e06df57e23 100644
--- a/src/common/slurm_protocol_defs.c
+++ b/src/common/slurm_protocol_defs.c
@@ -885,31 +885,31 @@ void slurm_free_submit_response_response_msg(submit_response_msg_t * msg)
 void slurm_free_ctl_conf(slurm_ctl_conf_info_msg_t * config_ptr)
 {
 	if (config_ptr) {
-		xfree(config_ptr->authtype);
-		xfree(config_ptr->accounting_storage_type);
-		xfree(config_ptr->accounting_storage_user);
-		xfree(config_ptr->accounting_storage_host);
-		xfree(config_ptr->accounting_storage_pass);
-		xfree(config_ptr->backup_addr);
-		xfree(config_ptr->backup_controller);
-		xfree(config_ptr->checkpoint_type);
-		xfree(config_ptr->cluster_name);
-		xfree(config_ptr->control_addr);
-		xfree(config_ptr->control_machine);
-		xfree(config_ptr->crypto_type);
+		xfree (config_ptr->accounting_storage_host);
+		xfree (config_ptr->accounting_storage_pass);
+		xfree (config_ptr->accounting_storage_type);
+		xfree (config_ptr->accounting_storage_user);
+		xfree (config_ptr->authtype);
+		xfree (config_ptr->backup_addr);
+		xfree (config_ptr->backup_controller);
+		xfree (config_ptr->checkpoint_type);
+		xfree (config_ptr->cluster_name);
+		xfree (config_ptr->control_addr);
+		xfree (config_ptr->control_machine);
+		xfree (config_ptr->crypto_type);
 		xfree(config_ptr->epilog);
 		xfree(config_ptr->health_check_program);
 		xfree(config_ptr->job_acct_gather_type);
+		xfree(config_ptr->job_acct_storage_host);
 		xfree(config_ptr->job_acct_storage_loc);
+		xfree(config_ptr->job_acct_storage_pass);
 		xfree(config_ptr->job_acct_storage_type);
 		xfree(config_ptr->job_acct_storage_user);
-		xfree(config_ptr->job_acct_storage_host);
-		xfree(config_ptr->job_acct_storage_pass);
+		xfree(config_ptr->job_comp_host);
 		xfree(config_ptr->job_comp_loc);
+		xfree(config_ptr->job_comp_pass);
 		xfree(config_ptr->job_comp_type);
 		xfree(config_ptr->job_comp_user);
-		xfree(config_ptr->job_comp_host);
-		xfree(config_ptr->job_comp_pass);
 		xfree(config_ptr->job_credential_private_key);
 		xfree(config_ptr->job_credential_public_certificate);
 		xfree(config_ptr->licenses);
@@ -929,11 +929,12 @@ void slurm_free_ctl_conf(slurm_ctl_conf_info_msg_t * config_ptr)
 		xfree(config_ptr->slurm_conf);
 		xfree(config_ptr->slurm_user_name);
 		xfree(config_ptr->slurmctld_pidfile);
-		xfree(config_ptr->slurmctld_logfile);
+		xfree(config_ptr->slurmctld_logfile);;
 		xfree(config_ptr->slurmd_logfile);
 		xfree(config_ptr->slurmd_pidfile);
 		xfree(config_ptr->slurmd_spooldir);
 		xfree(config_ptr->slurmdbd_addr);
+		xfree(config_ptr->slurmdbd_auth_info);
 		xfree(config_ptr->srun_epilog);
 		xfree(config_ptr->srun_prolog);
 		xfree(config_ptr->state_save_location);
diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c
index 0cd61f3b95a..efdaa5f6d7f 100644
--- a/src/common/slurm_protocol_pack.c
+++ b/src/common/slurm_protocol_pack.c
@@ -2510,6 +2510,10 @@ _unpack_slurm_ctl_conf_msg(slurm_ctl_conf_info_msg_t **
 	return SLURM_SUCCESS;
 
 unpack_error:
+	xfree(build_ptr->accounting_storage_host);
+	xfree(build_ptr->accounting_storage_pass);
+	xfree(build_ptr->accounting_storage_type);
+	xfree(build_ptr->accounting_storage_user);
 	xfree(build_ptr->authtype);
 	xfree(build_ptr->backup_addr);
 	xfree(build_ptr->backup_controller);
@@ -2521,16 +2525,16 @@ unpack_error:
 	xfree(build_ptr->epilog);
 	xfree(build_ptr->health_check_program);
 	xfree(build_ptr->job_acct_gather_type);
+	xfree(build_ptr->job_acct_storage_host);
 	xfree(build_ptr->job_acct_storage_loc);
+	xfree(build_ptr->job_acct_storage_pass);
 	xfree(build_ptr->job_acct_storage_type);
 	xfree(build_ptr->job_acct_storage_user);
-	xfree(build_ptr->job_acct_storage_host);
-	xfree(build_ptr->job_acct_storage_pass);
+	xfree(build_ptr->job_comp_host);
 	xfree(build_ptr->job_comp_loc);
+	xfree(build_ptr->job_comp_pass);
 	xfree(build_ptr->job_comp_type);
 	xfree(build_ptr->job_comp_user);
-	xfree(build_ptr->job_comp_host);
-	xfree(build_ptr->job_comp_pass);
 	xfree(build_ptr->job_credential_private_key);
 	xfree(build_ptr->job_credential_public_certificate);
 	xfree(build_ptr->health_check_program);
-- 
GitLab