diff options
author | Sami Kerola | 2013-07-07 21:54:43 +0200 |
---|---|---|
committer | Karel Zak | 2013-07-09 14:25:13 +0200 |
commit | 21c4058d92f5f17b87c62063eb77d126be08bd0e (patch) | |
tree | 51fb2d2c05f1a54f0958721a6b01446400a5ca38 /login-utils/sulogin-consoles.c | |
parent | sfdisk: assigned value is never read [clang-analyzer] (diff) | |
download | kernel-qcow2-util-linux-21c4058d92f5f17b87c62063eb77d126be08bd0e.tar.gz kernel-qcow2-util-linux-21c4058d92f5f17b87c62063eb77d126be08bd0e.tar.xz kernel-qcow2-util-linux-21c4058d92f5f17b87c62063eb77d126be08bd0e.zip |
sulogin: fix memory leak [clang-analyzer]
And make code a little bit more robust.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/sulogin-consoles.c')
-rw-r--r-- | login-utils/sulogin-consoles.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/login-utils/sulogin-consoles.c b/login-utils/sulogin-consoles.c index d0f0eab2b..a131e7974 100644 --- a/login-utils/sulogin-consoles.c +++ b/login-utils/sulogin-consoles.c @@ -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)) |