]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
initutils: Fix memleak on realloc failure 2999/head
authorRikard Falkeborn <rikard.falkeborn@gmail.com>
Sun, 12 May 2019 00:22:15 +0000 (02:22 +0200)
committerRikard Falkeborn <rikard.falkeborn@gmail.com>
Sun, 12 May 2019 01:16:39 +0000 (03:16 +0200)
Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
src/lxc/initutils.c

index a55d8b2860d622acae041c31e80d29bee88f6c59..da336329409c5f6954e8809eb9067f630c7a2cac 100644 (file)
@@ -242,7 +242,7 @@ int setproctitle(char *title)
 {
        __do_fclose FILE *f = NULL;
        int i, fd, len;
-       char *buf_ptr;
+       char *buf_ptr, *tmp_proctitle;
        char buf[LXC_LINELEN];
        int ret = 0;
        ssize_t bytes_read = 0;
@@ -305,10 +305,12 @@ int setproctitle(char *title)
         * want to have room for it. */
        len = strlen(title) + 1;
 
-       proctitle = realloc(proctitle, len);
-       if (!proctitle)
+       tmp_proctitle = realloc(proctitle, len);
+       if (!tmp_proctitle)
                return -1;
 
+       proctitle = tmp_proctitle;
+
        arg_start = (unsigned long)proctitle;
        arg_end = arg_start + len;