This was found by reading the code while investigating issue #96 and not
verified with any tools:

If `child->pid` is falsy `child` will be freed instead of being added to
`proc_list`. The setting of `PROC_O_LEAVING` happens unconditionally after
this check.

Fix the issue by mising the setting of the LEAVING option right behind the
allocation of `child`.

This bug was introduced in 4528611ed66d8bfa344782f6c7f1e7151cf48bf5, which
is specific to the 2.0-dev branch. No backport required.
---
 src/mworker.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/mworker.c b/src/mworker.c
index 8df748d3f..491d40837 100644
--- a/src/mworker.c
+++ b/src/mworker.c
@@ -147,6 +147,9 @@ void mworker_env_to_proc_list()
 
                child = calloc(1, sizeof(*child));
 
+               /* this is a process inherited from a reload that should be 
leaving */
+               child->options |= PROC_O_LEAVING;
+
                while ((subtoken = strtok_r(token, ";", &s2))) {
 
                        token = NULL;
@@ -184,10 +187,7 @@ void mworker_env_to_proc_list()
                } else {
                        free(child->id);
                        free(child);
-
                }
-               /* this is a process inherited from a reload that should be 
leaving */
-               child->options |= PROC_O_LEAVING;
        }
 
        unsetenv("HAPROXY_PROCESSES");
-- 
2.21.0


Reply via email to