]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sulogin: fix memory leak [clang-analyzer]
authorSami Kerola <kerolasa@iki.fi>
Sun, 7 Jul 2013 19:54:43 +0000 (20:54 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 30 Jul 2013 09:13:47 +0000 (11:13 +0200)
And make code a little bit more robust.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/sulogin-consoles.c

index d0f0eab2be768b2e7a299d49c288b62a95f1cbd9..a131e797428fb8bb5218204e7f611e9591fa2aab 100644 (file)
@@ -719,7 +719,7 @@ console:
 
 fallback:
        if (fallback >= 0) {
-               const char *name;
+               const char *name, *n;
                struct console *console;
 
                if (device && *device != '\0')
@@ -729,7 +729,11 @@ fallback:
                if (!name)
                        name = "/dev/tty";
 
-               rc = append_console(consoles, strdup(name));
+               n = strdup(name);
+               if (!n)
+                       return -ENOMEM;
+               rc = append_console(consoles, n);
+               free(n);
                if (rc < 0)
                        return rc;
                if (list_empty(consoles))