ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
5d2ee9
From ceacf935ac9f59bc08b5901f70f227958a2bcf52 Mon Sep 17 00:00:00 2001
5d2ee9
From: Yu Watanabe <watanabe.yu+github@gmail.com>
5d2ee9
Date: Tue, 28 May 2019 18:07:01 +0900
5d2ee9
Subject: [PATCH] journal: use cleanup attribute at one more place
5d2ee9
5d2ee9
(cherry picked from commit 627df1dc42b68a74b0882b06366d1185b1a34332)
5d2ee9
5d2ee9
Conflicts:
5d2ee9
	src/journal/journald-server.c
5d2ee9
5d2ee9
Related: #1788085
5d2ee9
---
5d2ee9
 src/journal/journal-file.h    | 1 +
5d2ee9
 src/journal/journald-server.c | 9 ++++-----
5d2ee9
 2 files changed, 5 insertions(+), 5 deletions(-)
5d2ee9
5d2ee9
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
5d2ee9
index cd8a48a364..6a44fd39d2 100644
5d2ee9
--- a/src/journal/journal-file.h
5d2ee9
+++ b/src/journal/journal-file.h
5d2ee9
@@ -144,6 +144,7 @@ int journal_file_open(
5d2ee9
 int journal_file_set_offline(JournalFile *f, bool wait);
5d2ee9
 bool journal_file_is_offlining(JournalFile *f);
5d2ee9
 JournalFile* journal_file_close(JournalFile *j);
5d2ee9
+DEFINE_TRIVIAL_CLEANUP_FUNC(JournalFile*, journal_file_close);
5d2ee9
 
5d2ee9
 int journal_file_open_reliably(
5d2ee9
                 const char *fname,
5d2ee9
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
5d2ee9
index 6250eab831..7632e2d9d0 100644
5d2ee9
--- a/src/journal/journald-server.c
5d2ee9
+++ b/src/journal/journald-server.c
5d2ee9
@@ -253,8 +253,9 @@ static int open_journal(
5d2ee9
                 bool seal,
5d2ee9
                 JournalMetrics *metrics,
5d2ee9
                 JournalFile **ret) {
5d2ee9
+
5d2ee9
+        _cleanup_(journal_file_closep) JournalFile *f = NULL;
5d2ee9
         int r;
5d2ee9
-        JournalFile *f;
5d2ee9
 
5d2ee9
         assert(s);
5d2ee9
         assert(fname);
5d2ee9
@@ -271,12 +272,10 @@ static int open_journal(
5d2ee9
                 return r;
5d2ee9
 
5d2ee9
         r = journal_file_enable_post_change_timer(f, s->event, POST_CHANGE_TIMER_INTERVAL_USEC);
5d2ee9
-        if (r < 0) {
5d2ee9
-                (void) journal_file_close(f);
5d2ee9
+        if (r < 0)
5d2ee9
                 return r;
5d2ee9
-        }
5d2ee9
 
5d2ee9
-        *ret = f;
5d2ee9
+        *ret = TAKE_PTR(f);
5d2ee9
         return r;
5d2ee9
 }
5d2ee9