[PATCH] mesg.c: make tty variable use only dynamic memory

Alexey Fomenko ext-alexey.fomenko at nokia.com
Mon Mar 21 09:46:49 UTC 2011


Ok, how about this version? 

> Overall I agree with other posters: patch doesn't improve anything.
> 

---
 init/mesg.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/init/mesg.c b/init/mesg.c
index ca230f3..c36c038 100644
--- a/init/mesg.c
+++ b/init/mesg.c
@@ -19,7 +19,7 @@ int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int mesg_main(int argc, char **argv)
 {
 	struct stat sb;
-	const char *tty;
+	char *tty;
 	char c = 0;
 
 	if (--argc == 0
@@ -27,20 +27,26 @@ int mesg_main(int argc, char **argv)
 	) {
 		tty = xmalloc_ttyname(STDERR_FILENO);
 		if (tty == NULL) {
-			tty = "ttyname";
+			tty = xstrdup("ttyname");
 		} else if (stat(tty, &sb) == 0) {
 			mode_t m;
 			if (argc == 0) {
 				puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
-				return EXIT_SUCCESS;
+				goto success;
 			}
 			m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
 			               : sb.st_mode & ~(S_IWGRP|S_IWOTH);
 			if (chmod(tty, m) == 0) {
-				return EXIT_SUCCESS;
+				goto success;
 			}
 		}
 		bb_simple_perror_msg_and_die(tty);
 	}
 	bb_show_usage();
+
+	success:
+#if ENABLE_FEATURE_CLEAN_UP
+	free(tty);
+#endif
+	return EXIT_SUCCESS;
 }
-- 
1.7.3.4






More information about the busybox mailing list