]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker: fix memory leak due to master-worker fork
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Tue, 15 Oct 2024 10:39:50 +0000 (12:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Oct 2024 20:02:39 +0000 (22:02 +0200)
Before this fix, startup logs ring was duplicated before the fork(), so master
and worker had both the original startup_logs ring and the duplicated one. In
the worker context we freed the original ring and used a duplicated one. In
the master context we did nothing, but we still create a duplicated copy again
and again during the reload.

So, let's duplicate startup logs ring only in the worker context. Master
continues to use the original ring initialized in init() before its fork().

src/haproxy.c

index 66e2724fc5ef1e40f364759f887b586c4fd6777d..686e16ac3a73a970325c811221e8c5a5c62358b6 100644 (file)
@@ -2151,8 +2151,6 @@ static void init(int argc, char **argv)
                struct mworker_proc *child;
                struct ring *tmp_startup_logs = NULL;
 
-               /* at this point the worker must have his own startup_logs buffer */
-               tmp_startup_logs = startup_logs_dup(startup_logs);
                worker_pid = fork();
                switch (worker_pid) {
                case -1:
@@ -2160,7 +2158,11 @@ static void init(int argc, char **argv)
 
                        exit(EXIT_FAILURE);
                case 0:
-                       /* in child */
+                       /* in child: at this point the worker must have his own startup_logs buffer */
+                       tmp_startup_logs = startup_logs_dup(startup_logs);
+                       if (tmp_startup_logs == NULL)
+                               exit(EXIT_FAILURE);
+
                        startup_logs_free(startup_logs);
                        startup_logs = tmp_startup_logs;
                        /* This one must not be exported, it's internal! */