dcavalca / rpms / systemd

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