ryantimwilson / rpms / systemd

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