diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/load-fragment.c | 8 | ||||
-rw-r--r-- | src/core/main.c | 26 | ||||
-rw-r--r-- | src/shared/log.c | 6 |
3 files changed, 16 insertions, 24 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 2a21727c6c..6839da8817 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -1314,7 +1314,7 @@ int config_parse_path_spec(const char *unit, Path *p = data; PathSpec *s; PathType b; - char *k; + char _cleanup_free_ *k = NULL; assert(filename); assert(lvalue); @@ -1348,17 +1348,15 @@ int config_parse_path_spec(const char *unit, if (!path_is_absolute(k)) { log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Path is not absolute, ignoring: %s", k); - free(k); return 0; } s = new0(PathSpec, 1); - if (!s) { - free(k); + if (!s) return log_oom(); - } s->path = path_kill_slashes(k); + k = NULL; s->type = b; s->inotify_fd = -1; diff --git a/src/core/main.c b/src/core/main.c index 2043345eca..f19e432d4a 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -688,7 +688,8 @@ static int parse_config_file(void) { } static int parse_proc_cmdline(void) { - char *line, *w, *state; + char _cleanup_free_ *line = NULL; + char *w, *state; int r; size_t l; @@ -697,34 +698,27 @@ static int parse_proc_cmdline(void) { if (detect_container(NULL) > 0) return 0; - if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) { + r = read_one_line_file("/proc/cmdline", &line); + if (r < 0) { log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); return 0; } FOREACH_WORD_QUOTED(w, l, line, state) { - char *word; + char _cleanup_free_ *word; - if (!(word = strndup(w, l))) { - r = -ENOMEM; - goto finish; - } + word = strndup(w, l); + if (!word) + return log_oom(); r = parse_proc_cmdline_word(word); if (r < 0) { log_error("Failed on cmdline argument %s: %s", word, strerror(-r)); - free(word); - goto finish; + return r; } - - free(word); } - r = 0; - -finish: - free(line); - return r; + return 0; } static int parse_argv(int argc, char *argv[]) { diff --git a/src/shared/log.c b/src/shared/log.c index 876f22dfc5..27317f7ed3 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -737,7 +737,9 @@ int log_struct_internal( char header[LINE_MAX]; struct iovec iovec[17] = {}; unsigned n = 0, i; - struct msghdr mh; + struct msghdr mh = { + .msg_iov = iovec, + }; static const char nl = '\n'; /* If the journal is available do structured logging */ @@ -775,8 +777,6 @@ int log_struct_internal( format = va_arg(ap, char *); } - zero(mh); - mh.msg_iov = iovec; mh.msg_iovlen = n; if (sendmsg(journal_fd, &mh, MSG_NOSIGNAL) < 0) |