journal: do not trigger assertion when journal_file_close() get NULL
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 May 2019 03:40:17 +0000 (12:40 +0900)
committerThe Plumber <50238977+systemd-rhel-bot@users.noreply.github.com>
Thu, 27 Feb 2020 09:12:37 +0000 (10:12 +0100)
We generally expect destructors to not complain if a NULL argument is passed.

Closes #12400.

(cherry picked from commit c377a6f3ad3d9bed4ce7e873e8e9ec6b1650c57d)
(cherry picked from commit dc4c3a5aa35a5e88adcf210471d9460262c8c0d9)
Resolves: #1807350

src/journal/journal-file.c
src/journal/journald-server.c

index efc3ee052b260ae3b3c506488016fa4a02145858..8249b11b234c50d0f1783c8af35bd58873c0c79c 100644 (file)
@@ -335,7 +335,8 @@ bool journal_file_is_offlining(JournalFile *f) {
 }
 
 JournalFile* journal_file_close(JournalFile *f) {
-        assert(f);
+        if (!f)
+                return NULL;
 
 #if HAVE_GCRYPT
         /* Write the final tag */
index f2d2856e031f3785e46860e4b2c87197f59bf7ba..31a7b5ff0372093446e2f0b99a86be24332c5e12 100644 (file)
@@ -1906,11 +1906,8 @@ void server_done(Server *s) {
 
         client_context_flush_all(s);
 
-        if (s->system_journal)
-                (void) journal_file_close(s->system_journal);
-
-        if (s->runtime_journal)
-                (void) journal_file_close(s->runtime_journal);
+        (void) journal_file_close(s->system_journal);
+        (void) journal_file_close(s->runtime_journal);
 
         ordered_hashmap_free_with_destructor(s->user_journals, journal_file_close);