From 21f3c8db00f0d4a3f0989559847d2564f4c73a11 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 20 Oct 2014 19:56:05 -0500 Subject: [PATCH] More static analysis fixes from Ashwini Sharma. --- lib/xwrap.c | 1 + toys/other/netcat.c | 1 - toys/pending/modprobe.c | 12 +++++++++--- toys/posix/nohup.c | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/xwrap.c b/lib/xwrap.c index b7eb274..6216d91 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -94,6 +94,7 @@ void xprintf(char *format, ...) va_start(va, format); vprintf(format, va); + va_end(va); if (fflush(stdout) || ferror(stdout)) perror_exit("write"); } diff --git a/toys/other/netcat.c b/toys/other/netcat.c index 3c6f630..485dda1 100644 --- a/toys/other/netcat.c +++ b/toys/other/netcat.c @@ -166,7 +166,6 @@ void netcat_main(void) if (!child && toys.optc) { int fd = pollfds[0].fd; - if (!temp) close(sockfd); dup2(fd, 0); dup2(fd, 1); if (toys.optflags&FLAG_L) dup2(fd, 2); diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c index cbf929b..5431cb3 100644 --- a/toys/pending/modprobe.c +++ b/toys/pending/modprobe.c @@ -178,15 +178,21 @@ static int read_line(FILE *fl, char **li) line = NULL; linelen = nxtlinelen = 0; len = getline(&line, (size_t*)&linelen, fl); - if (len <= 0) return len; + if (len <= 0) { + free(line); + return len; + } // checking for commented lines. if (line[0] != '#') break; free(line); } for (;;) { if (line[len - 1] == '\n') len--; - // checking line continuation. - if (!len || line[len - 1] != '\\') break; + if (!len) { + free(line); + return len; + } else if (line[len - 1] != '\\') break; + len--; nxtlen = getline(&nxtline, (size_t*)&nxtlinelen, fl); if (nxtlen <= 0) break; diff --git a/toys/posix/nohup.c b/toys/posix/nohup.c index 0cece0b..df264da 100644 --- a/toys/posix/nohup.c +++ b/toys/posix/nohup.c @@ -28,8 +28,10 @@ void nohup_main(void) S_IRUSR|S_IWUSR )) { char *temp = getenv("HOME"); + temp = xmprintf("%s/%s", temp ? temp : "", "nohup.out"); xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, 0600); + free(temp); } } if (isatty(0)) { -- 2.7.4