[PATCH 28/34] sulogin: fix memory leak [clang-analyzer]

Sami Kerola
2013-07-07T19:56:22Z

And make code a little bit more robust.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/sulogin-consoles.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/login-utils/sulogin-consoles.c b/login-utils/sulogin-consoles.c
index d0f0eab..a131e79 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))
--
1.8.3.2