From: Zbigniew Jędrzejewski-Szmek Date: Sun, 20 May 2018 20:13:08 +0000 (+0200) Subject: shared/logs-show: use _cleanup_ X-Git-Tag: v239~172^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9be391d4dbe1e5f83e44486c1a2a91ab0327be6c;p=thirdparty%2Fsystemd.git shared/logs-show: use _cleanup_ --- diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 124fa838b3c..365c9130097 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -862,12 +862,10 @@ static int output_json( } } } - if (r == -EBADMSG) { log_debug_errno(r, "Skipping message we can't read: %m"); return 0; } - if (r < 0) return r; @@ -877,7 +875,8 @@ static int output_json( SD_JOURNAL_FOREACH_DATA(j, data, length) { const char *eq; - char *kk, *n; + char *kk; + _cleanup_free_ char *n = NULL; size_t m; unsigned u; @@ -890,33 +889,24 @@ static int output_json( continue; m = eq - (const char*) data; - n = memdup_suffix0(data, m); if (!n) { r = log_oom(); goto finish; } - if (output_fields && !set_get(output_fields, n)) { - free(n); + if (output_fields && !set_get(output_fields, n)) continue; - } - if (separator) { - if (mode == OUTPUT_JSON_PRETTY) - fputs(",\n\t", f); - else - fputs(", ", f); - } + if (separator) + fputs(mode == OUTPUT_JSON_PRETTY ? ",\n\t" : ", ", f); u = PTR_TO_UINT(hashmap_get2(h, n, (void**) &kk)); - if (u == 0) { + if (u == 0) /* We already printed this, let's jump to the next */ - free(n); separator = false; - continue; - } else if (u == 1) { + else if (u == 1) { /* Field only appears once, output it directly */ json_escape(f, data, m, flags); @@ -926,12 +916,9 @@ static int output_json( hashmap_remove(h, n); free(kk); - free(n); separator = true; - continue; - } else { /* Field appears multiple times, output it as array */ json_escape(f, data, m, flags); @@ -958,7 +945,6 @@ static int output_json( hashmap_remove(h, n); free(kk); - free(n); /* Iterate data fields form the beginning */ done = false;