richardphibel / rpms / systemd

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