Ticket 9967

Summary: Functions build_alloc_msg and slurm_free_resource_allocation_response_msg are inconsistent
Product: Slurm Reporter: Anatoly M <mukav>
Component: slurmctldAssignee: Jacob Jenson <jacob>
Status: RESOLVED INVALID QA Contact:
Severity: 6 - No support contract    
Priority: --- CC: mukav
Version: 20.02.3   
Hardware: Linux   
OS: Linux   
Site: -Other- Alineos Sites: ---
Atos/Eviden Sites: --- Confidential Site: ---
Coreweave sites: --- Cray Sites: ---
DS9 clusters: --- HPCnow Sites: ---
HPE Sites: --- IBM Sites: ---
NOAA SIte: --- OCF Sites: ---
Recursion Pharma Sites: --- SFW Sites: ---
SNIC sites: --- Linux Distro: ---
Machine Name: CLE Version:
Version Fixed: Target Release: ---
DevPrio: --- Emory-Cloud Sites: ---

Description Anatoly M 2020-10-09 08:05:49 MDT
Hi guys,

We found an interesting thing in your code. 
Functions build_alloc_msg and slurm_free_resource_allocation_response_msg are inconsistent.
Variable msg->environment created in build_alloc_msg is deleted incorrectly in 
slurm_free_resource_allocation_response_msg.
This led to the inoperability of the  job_ptr->details->env_sup structure filling mechanism
in the selection plugin.

Everything works fine if we apply this patch:

--- slurm-20.02.3.clean/src/slurmctld/proc_req.c      2020-05-21 23:34:01.000000000 +0300
+++ slurm-20.02.3/src/slurmctld/proc_req.c          2020-10-08 23:02:32.189548100 +0300
@@ -1295,11 +1295,12 @@
                if (job_ptr->details->env_cnt) {
                        alloc_msg->env_size = job_ptr->details->env_cnt;
                        alloc_msg->environment =
-                               xmalloc(sizeof(char *) * alloc_msg->env_size);
+                               xmalloc(sizeof(char *) * (alloc_msg->env_size + 1));
                        for (i = 0; i < alloc_msg->env_size; i++) {
                                alloc_msg->environment[i] =
                                        xstrdup(job_ptr->details->env_sup[i]);
                        }
+                       alloc_msg->environment[alloc_msg->env_size] = NULL;
                }
        } else {
                /* alloc_msg->pn_min_memory = 0; */