richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
1abbee
From 76d6062ebf93614a45f1f74be7a93a9a662c5812 Mon Sep 17 00:00:00 2001
1abbee
From: Lennart Poettering <lennart@poettering.net>
1abbee
Date: Tue, 19 May 2015 00:35:02 +0200
1abbee
Subject: [PATCH] journalctl: unify how we free boot id lists a bit
1abbee
1abbee
Instead of use LIST_FOREACH_SAFE, just use the same, seperate destructor
1abbee
everywhere.
1abbee
1abbee
Cherry-picked from: 9530e0d023b0e9308f19eadf6e42cdc25bc30793
1abbee
Related: #1318994
1abbee
---
1abbee
 src/journal/journalctl.c | 21 +++++++++++++++------
1abbee
 1 file changed, 15 insertions(+), 6 deletions(-)
1abbee
1abbee
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
c62b8e
index ba9ae05f72..5864ff50a6 100644
1abbee
--- a/src/journal/journalctl.c
1abbee
+++ b/src/journal/journalctl.c
1abbee
@@ -932,6 +932,15 @@ static int add_matches(sd_journal *j, char **args) {
1abbee
         return 0;
1abbee
 }
1abbee
 
1abbee
+static void boot_id_free_all(BootId *l) {
1abbee
+
1abbee
+        while (l) {
1abbee
+                BootId *i = l;
1abbee
+                LIST_REMOVE(boot_list, l, i);
1abbee
+                free(i);
1abbee
+        }
1abbee
+}
1abbee
+
1abbee
 static int discover_next_boot(
1abbee
                 sd_journal *j,
1abbee
                 BootId **boot,
1abbee
@@ -1009,6 +1018,7 @@ static int discover_next_boot(
1abbee
 
1abbee
         *boot = next_boot;
1abbee
         next_boot = NULL;
1abbee
+
1abbee
         return 0;
1abbee
 }
1abbee
 
1abbee
@@ -1080,9 +1090,7 @@ static int get_boots(
1abbee
 
1abbee
                 r = discover_next_boot(j, &current, advance_older, !query_ref_boot);
1abbee
                 if (r < 0) {
1abbee
-                        BootId *id, *id_next;
1abbee
-                        LIST_FOREACH_SAFE(boot_list, id, id_next, head)
1abbee
-                                free(id);
1abbee
+                        boot_id_free_all(head);
1abbee
                         return r;
1abbee
                 }
1abbee
 
1abbee
@@ -1118,7 +1126,7 @@ finish:
1abbee
 
1abbee
 static int list_boots(sd_journal *j) {
1abbee
         int w, i, count;
1abbee
-        BootId *id, *id_next, *all_ids;
1abbee
+        BootId *id, *all_ids;
1abbee
 
1abbee
         assert(j);
1abbee
 
1abbee
@@ -1132,7 +1140,7 @@ static int list_boots(sd_journal *j) {
1abbee
         w = DECIMAL_STR_WIDTH(count - 1) + 1;
1abbee
 
1abbee
         i = 0;
1abbee
-        LIST_FOREACH_SAFE(boot_list, id, id_next, all_ids) {
1abbee
+        LIST_FOREACH(boot_list, id, all_ids) {
1abbee
                 char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX];
1abbee
 
1abbee
                 printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n",
1abbee
@@ -1141,9 +1149,10 @@ static int list_boots(sd_journal *j) {
1abbee
                        format_timestamp_maybe_utc(a, sizeof(a), id->first),
1abbee
                        format_timestamp_maybe_utc(b, sizeof(b), id->last));
1abbee
                 i++;
1abbee
-                free(id);
1abbee
         }
1abbee
 
1abbee
+        boot_id_free_all(all_ids);
1abbee
+
1abbee
         return 0;
1abbee
 }
1abbee