]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: systemd: check return value of calloc()
authorWilly Tarreau <w@1wt.eu>
Tue, 25 Oct 2016 15:05:56 +0000 (17:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 25 Oct 2016 15:36:40 +0000 (17:36 +0200)
The wrapper is not the best reliable thing in the universe, so start
by adding at least the minimum expected controls :-/

To be backported to 1.5 and 1.6.

src/haproxy-systemd-wrapper.c

index 84d2e176f96a94e509810024b78a8998b9bafa90..15c48caea56112d0b3c688b6fcd17d098ebce3b8 100644 (file)
@@ -77,11 +77,17 @@ static void spawn_haproxy(char **pid_strv, int nb_pid)
 
        pid = fork();
        if (!pid) {
-               /* 3 for "haproxy -Ds -sf" */
-               char **argv = calloc(4 + main_argc + nb_pid + 1, sizeof(char *));
+               char **argv;
                int i;
                int argno = 0;
 
+               /* 3 for "haproxy -Ds -sf" */
+               argv = calloc(4 + main_argc + nb_pid + 1, sizeof(char *));
+               if (!argv) {
+                       fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: failed to calloc(), please try again later.\n");
+                       exit(1);
+               }
+
                reset_signal_handler();
                locate_haproxy(haproxy_bin, 512);
                argv[argno++] = haproxy_bin;