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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



And make code a little bit more robust.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux