From 4ad16808c02e3eb6c1ec8500b3d086cc28e9b75a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 16 Jul 2013 14:45:28 -0400 Subject: [PATCH] journalctl,systemctl: fix tiny memleak --- src/journal/journalctl.c | 7 ++++++- src/journal/sd-journal.c | 2 +- src/shared/logs-show.c | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 7415abc..7099706 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1408,7 +1408,12 @@ int main(int argc, char *argv[]) { if (r < 0) return EXIT_FAILURE; - log_debug("Journal filter: %s", j->level0 ? journal_make_match_string(j) : "none"); + if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { + _cleanup_free_ char *filter; + + filter = journal_make_match_string(j); + log_debug("Journal filter: %s", filter); + } if (arg_field) { const void *data; diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 81b0c136..a83c0c2 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -362,7 +362,7 @@ static char *match_make_string(Match *m) { bool enclose = false; if (!m) - return strdup(""); + return strdup("none"); if (m->type == MATCH_DISCRETE) return strndup(m->data, m->size); diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 8dc11bb..ea47468 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1059,7 +1059,12 @@ int show_journal_by_unit( if (r < 0) return r; - log_debug("Journal filter: %s", journal_make_match_string(j)); + if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { + _cleanup_free_ char *filter; + + filter = journal_make_match_string(j); + log_debug("Journal filter: %s", filter); + } r = show_journal(f, j, mode, n_columns, not_before, how_many, flags); if (r < 0) -- 2.7.4